• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strings & Tokens vs Integers

 
Sam Bluesman
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Jaime M. Tovar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic