Hello, I was wondering if it was possible (and if is, how) to:
Basically have the user enter data in the form:
"[num1, num 2] [num3, num4]"
and then assign num1, num2, num3, num4 to the value that they entered. I realise that the input will not be in one or two characters so I somehow need a way to get the value of any length of characters between the brackets and the comma. Thank you for any help.
posted 11 years ago
Hi, welcome to the ranch!
I think you're getting into the area of parsing strings. There are many ways to do it. The first you might try is to find substrings:
If you haven't done this before, it's a pretty good exercise. It will give you some techniques you can keep "in your pocket" in case you need them one day.
You can do more sophisticated parsing (in fewer lines of code!) with StringTokenizer, String.split(), regular expressions or Scanner. Try the first method to get something going, post some code to let us see what format you put the results into. Then we can explore the other methods.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
You've gotta fight it! Don't give in! Read this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user