• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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

 
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();
}
 
High Plains Drifter
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
 
Wanna see my flashlight? How about this tiny ad?
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!