Link to home
Start Free TrialLog in
Avatar of ssdjgru1
ssdjgru1

asked on

StreamTokenizer separators...

I would like to know how to set to which separators the StreamTokenizer will "react". It is easy to set separatorst for StringTokenizer but it doesn't work with StreamTokenizer in that way.
ASKER CERTIFIED SOLUTION
Avatar of Laminamia063099
Laminamia063099

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ssdjgru1
ssdjgru1

ASKER

hmm...there is no whiteSpace method in java.io.StreamTokenizer class.
There is whitespaceChars(int,int),void method  but I don't know how to use it.
Oops.  Sorry that's the one I meant.  the whitespaceChars(int, int) method allows you to specify a range of characters that are considered to be whitespace (whitespace characters that you specify are your tokens.)

The following code:

            StreamTokenizer st = new StreamTokenizer(new BufferedReader(new FileReader("B.java")));
            st.whitespaceChars('|','|');

creates a StreamTokenizer that considers the characters from '|' to '|' (i.e. just '|') to be the only tokens in the StreamTokenizer.  That is how you set a token.

Use resetSyntax to reset the Tokenizer so that everything is considered "ordinary" (i.e. no tokens) and then set your own tokens using the whitespaceChars.

It does say that it takes int's, but by passing it characters, you are passing it the UNICODE value for those characters.

Good luck, drop a note if I'm still confusing :)

Laminamia :)