Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Roy Sin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic