wood burning stoves*
The moose likes Beginning Java and the fly likes Input within brackets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Input within brackets" Watch "Input within brackets" New topic
Author

Input within brackets

Nadee Anders
Greenhorn

Joined: Jul 01, 2005
Posts: 4
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.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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
 
wood burning stoves
 
subject: Input within brackets
 
Similar Threads
Help with sorting numbers
program assignment help
Integer Object Comparision Confusion
basic sql statement doubt
convert char to int in a string?