Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Input within brackets

 
Nadee Anders
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic