| Author |
extracting numeric values from string
|
Ron Isac
Greenhorn
Joined: Dec 22, 2004
Posts: 9
|
|
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
Joined: Mar 13, 2004
Posts: 1272
|
|
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.
|
Mike Gershman
SCJP 1.4, SCWCD in process
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
|
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.
|
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
|
 |
 |
|
|
subject: extracting numeric values from string
|
|
|