File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Parsing a String Program Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Parsing a String Program Help" Watch "Parsing a String Program Help" New topic
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: 606

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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parsing a String Program Help