Quick question on StreamTokenizer

O

overbored

How do I prevent StreamTokenizer from returning any TT_NUMBER items?
Basically all I want is to have a steady stream of plain TT_WORD items,
even if they're all digits. I tried wordChars('0', '9') but to no avail.
Thanks in advance.
 
B

Boudewijn Dijkstra

overbored said:
How do I prevent StreamTokenizer from returning any TT_NUMBER items?
Basically all I want is to have a steady stream of plain TT_WORD items,
even if they're all digits. I tried wordChars('0', '9') but to no avail.

This will just assign a group of chars to two types. Try calling
resetSyntax() first.
 
O

overbored

But won't that clear out *everything*? Then I'd have to rebuild the entire
table, and I would have to do research into locales and character sets and
whatnot.... Is there no alternative?
 
Y

Yakov

overbored said:
How do I prevent StreamTokenizer from returning any TT_NUMBER items?
Basically all I want is to have a steady stream of plain TT_WORD items,
even if they're all digits. I tried wordChars('0', '9') but to no avail.
Thanks in advance.

When you get TT_NUMBER, convert it to a String and concatenate all
strings and numbers into one string

Regards,
Yakov
 
B

Boudewijn Dijkstra

But won't that clear out *everything*? Then I'd have to rebuild the entire
table, and I would have to do research into locales and character sets and
whatnot....

That is what you might expect in Java, but quite the opposite is true:
StreamTokenizer isn't very advanced. It says in the docs: "Each byte read
from the input stream is regarded as a character in the range '\u0000' through
'\u00FF'." So there are only 256 characters to be reckoned for.
Is there no alternative?

I just read in the docs that the ordinaryChars() method does the same as
resetSyntax(), but only with the specified characters.

Remember this: javadoc is your friend.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top