• Post Reply Bookmark Topic Watch Topic
  • New Topic

extracting numeric values from string  RSS feed

 
Ron Isac
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a java program that has a string.The string contains different numers(multi digit) and characters. I want to extract these numbers into different variables.
for eg. if the string is c 32 34.
Then I want to extract c, 32 & 34.

Please help me . Thanks in advance.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pick off the fields with StringTokenizer.

To test if a field is a number, or whatever, you can use Integer.parseInt() inside a try/catch statement.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're in JDK 5 play with Scanner. By default it will pull tokens off a string delimited by spaces (just what you need) and convert them to various types if possible.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!