File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes extracting numeric values from string Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "extracting numeric values from string" Watch "extracting numeric values from string" New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: extracting numeric values from string
 
Similar Threads
How do I print a formatted number?
Help! Question on converting String to BigInteger
MessageFormat Help ?
regular expression question
AD LDS with DIGEST-MD5 can not connect