This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to read a word without bothering if it is a word or number Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "How to read a word without bothering if it is a word or number" Watch "How to read a word without bothering if it is a word or number" New topic
Author

How to read a word without bothering if it is a word or number

Roy Sin
Greenhorn

Joined: Sep 27, 2001
Posts: 2
hi
i have this problem... i am using the StreamTokenizer to read one word at a time... however, when i read words like 3G.. the StreamTokenizer will break up the 3 and G and read them seperately.. how do i solve this prob ? the code is as follows :
while (innerReader.ttype != StreamTokenizer.TT_EOF)
{
if (innerReader.ttype == StreamTokenizer.TT_WORD)
{
record = innerReader.sval;
record = record.toLowerCase();
}
else if (innerReader.ttype == StreamTokenizer.TT_NUMBER)
{
record=innerReader.nval;
}
System.out.println(record);
innerReader.nextToken();
}
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Hi Roy -
I haven't used the StreamTokenizer before, but the docs do say it reads a byte at a time; therein lies your problem.
To get the behavior you want, you'll probably have to read in a line at a time, and use the java.io.StringTokenizer class to parse it.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to read a word without bothering if it is a word or number
 
Similar Threads
StreamTokenizer
StreamTokenizer vs readLine
why i can't compare between streams ??
Importing large number of rows
StreamTokenizer