| Author |
Parsing a String Program Help
|
Nicole Miller
Greenhorn
Joined: Sep 08, 2011
Posts: 13
|
|
Hi, I'm looking for help on a program where the user enters a string of text (can be anything), and the program has to pull all the integers out of that string and put them in an array to be printed. I need to use a method to do this. So, for example, if the user inputted: sfd0jd-2jf93jf0, the array would need to contain 0,2,93,0. Here's what I have so far, but I'm now stuck and don't know what I'm doing wrong. Any advice would be great!
|
 |
Gamini Sirisena
Ranch Hand
Joined: Aug 05, 2008
Posts: 347
|
|
|
You could use a Scanner class with a delimiter with a pattern (a regular expression) to match non digits. I wrote a test program and got a print with about 4 lines with this approach.. hope this helps..
|
 |
Saifuddin Merchant
Ranch Hand
Joined: Feb 08, 2009
Posts: 576
|
|
Here's what your intParse() should do;
By the way this is pretty similar to you code which is almost correct, except for two facts.
1 it does not store the result 'temp' in tempArray
2. The lines
should have been
|
Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
|
 |
Nicole Miller
Greenhorn
Joined: Sep 08, 2011
Posts: 13
|
|
|
Thanks to both of you for the help! I'm all finished and it works great!
|
 |
 |
|
|
subject: Parsing a String Program Help
|
|
|