| Author |
Strings & Tokens vs Integers
|
Sam Bluesman
Ranch Hand
Joined: Nov 21, 2004
Posts: 188
|
|
I am at a stage where I have a text file and a program that is reading it. The text file contains a series of numbers seperated by a space. I want to read these numbers into my program and possibly store them into an array. Having limited knowledge and not seeimg to be able to find any documentation on the web i can use, using tokens SEEMS to be in the step in the right direction. I know these are used from strings and trying to retrieve words etc, and my thinking was obtain each number from the text file as a string and then convert them into integers in my program. Is it possible to do? If not, what other way is there to extract these numbers from the text file and store them as integers? Thanks [ October 28, 2005: Message edited by: Sam Bluesman ]
|
Moosey knows best
|
 |
Jaime M. Tovar
Ranch Hand
Joined: Mar 28, 2005
Posts: 133
|
|
|
If you have all the numbers in a string, and you know that all are separated by a space, you can use the split(� �) function. Applied over the String it will return a String array with each String representing a number. Then you can create an Integer with each String if you need it
|
She will remember your heart when men are fairy tales in books written by rabbits.<br /> As long as there is duct tape... there is also hope.
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
|
On JDK 5 read up on Scanner, too. It's a bit advanced with regular expressions, but very slick for reading tokens of a known type.
|
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: jrebel
|
|
subject: Strings & Tokens vs Integers
|
|
|