• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Input within brackets

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic