• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing a String Program Help

 
Nicole Miller
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nicole Miller
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to both of you for the help! I'm all finished and it works great!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic