Re: StreamTokenizer

Discussion in 'Java' started by Sudsy, Jul 24, 2003.

  1. Sudsy

    Sudsy Guest

    Ian deSouza wrote:
    > How do I avoid having the stream tokenizer parse digits?

    <snip>

    > With a file containing:
    > 12&3124 23-0 0-12-32
    >
    > I would like tokens: 12&3124 and 23-0 and 0-12-32


    In that case, why not use StringTokenizer? Read the input file
    using a BufferedReader (use the readLine method) and then parse
    each line.
     
    Sudsy, Jul 24, 2003
    #1
    1. Advertisements

  2. Sudsy

    Ian deSouza Guest

    Thanks for the suggestion, but things aren't necessarily line based,
    and I may switch (midstream) what I consider a token.

    Ian

    Sudsy <> wrote in message news:<>...
    > Ian deSouza wrote:
    > > How do I avoid having the stream tokenizer parse digits?

    > <snip>
    >
    > > With a file containing:
    > > 12&3124 23-0 0-12-32
    > >
    > > I would like tokens: 12&3124 and 23-0 and 0-12-32

    >
    > In that case, why not use StringTokenizer? Read the input file
    > using a BufferedReader (use the readLine method) and then parse
    > each line.
     
    Ian deSouza, Aug 1, 2003
    #2
    1. Advertisements

  3. Sudsy

    Sudsy Guest

    Ian deSouza wrote:
    > Thanks for the suggestion, but things aren't necessarily line based,
    > and I may switch (midstream) what I consider a token.
    >
    > Ian


    I beg your parsnips. How about this?

    StreamTokenizer st = null;

    try {
    st = new StreamTokenizer( new FileReader(
    some_file ) );
    // turn off special numeric interpretation
    st.ordinaryChars( '0', '9' );
    // all printable characters are word characters
    st.wordChars( 33, 126 );
    // all control characters are whitespace as
    // is the space character
    st.whitespaceChars( 0, 32 );
    while( st.nextToken() != StreamTokenizer.TT_EOF )
    System.out.println( st.sval );
    }
    catch( Exception e ) {
    // handle the usual problems
    }
     
    Sudsy, Aug 2, 2003
    #3
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. D. Lane
    Replies:
    1
    Views:
    2,700
    Dave Rathnow
    Jun 30, 2003
  2. JVarsoke
    Replies:
    1
    Views:
    1,817
    Dale King
    Oct 1, 2003
  3. Eric
    Replies:
    3
    Views:
    1,409
  4. Christian Bongiorno

    questions about StreamTokenizer

    Christian Bongiorno, May 9, 2004, in forum: Java
    Replies:
    9
    Views:
    879
    Roedy Green
    May 12, 2004
  5. overbored

    Quick question on StreamTokenizer

    overbored, Sep 20, 2004, in forum: Java
    Replies:
    4
    Views:
    481
    Boudewijn Dijkstra
    Sep 21, 2004
  6. ATC Productions
    Replies:
    3
    Views:
    2,803
    ATC Productions
    May 28, 2005
  7. Chris Berg
    Replies:
    5
    Views:
    5,192
    Roedy Green
    Nov 7, 2005
  8. Replies:
    1
    Views:
    5,176
    Brandon McCombs
    Dec 15, 2005
Loading...