Re: How does StreamTokenizer work

Discussion in 'Java' started by D. Lane, Jun 29, 2003.

  1. D. Lane

    D. Lane Guest

    Dave Rathnow ,

    Here is an example of how to use a StringTokenizer... which will
    print each value.

    You looked up the Javadoc for the StringTokenizer, right ?
    A google search for StringTokenizer finds a lot of
    the actual doc, remember to use the Force ('net using Google).

    Doug

    import java.util.*;

    public class stuf9 {

    public stuf9() {
    }

    /**
    * Quick and dirty example of StringTokenizer ()
    */
    static public void main(String[] args) {
    String hexString = "0b ab ff 33 56";

    StringTokenizer st = new StringTokenizer(hexString," ");
    System.out.println("<"+hexString+"> tokens="+st.countTokens());

    int cnt = 1;
    while ( st.hasMoreElements() )
    {
    System.out.println("Token "+cnt+" is <"+st.nextToken()+">");
    cnt ++;
    }

    st = new StringTokenizer(hexString," ", true);
    System.out.println("<"+hexString+"> w/delimits
    tokens="+st.countTokens());
    cnt = 1;
    while ( st.hasMoreElements() )
    {
    System.out.println("Token "+cnt+" is <"+st.nextToken()+">");
    cnt ++;
    }
    }
    }

    Dave Rathnow <> wrote in message
    news:LHqLa.41062$...
    > I have a text string of hex values separated by
    > whitespaces and I would like to read them using a
    > StreamTokenizer. For example:
    >
    > String hexString = "0b ab ff 33 56"
    >
    > I've been trying to figure out how to do it but haven't
    > had any luck. Can someone tell me how I setup a StreamTokenizer
    > to give me each hex value? That is, "0b" then "ab" then "ff"
    > etc.
    >
    > Thanks,
    > Dave.
    >
    > P.S. I know I can do this with a StringTokenizer but I don't necessarily
    > have my data in a String always.
    >
    >
     
    D. Lane, Jun 29, 2003
    #1
    1. Advertising

  2. D. Lane

    Dave Rathnow Guest

    Thanks,

    But that's not what I asked. I was asking about
    "StreamTokenizer", not "StringTokenizer"

    Dave.

    "D. Lane" <> wrote in message
    news:bdn9k9$klu$...
    > Dave Rathnow ,
    >
    > Here is an example of how to use a StringTokenizer... which will
    > print each value.
    >
    > You looked up the Javadoc for the StringTokenizer, right ?
    > A google search for StringTokenizer finds a lot of
    > the actual doc, remember to use the Force ('net using Google).
    >
    > Doug
    >
    > import java.util.*;
    >
    > public class stuf9 {
    >
    > public stuf9() {
    > }
    >
    > /**
    > * Quick and dirty example of StringTokenizer ()
    > */
    > static public void main(String[] args) {
    > String hexString = "0b ab ff 33 56";
    >
    > StringTokenizer st = new StringTokenizer(hexString," ");
    > System.out.println("<"+hexString+"> tokens="+st.countTokens());
    >
    > int cnt = 1;
    > while ( st.hasMoreElements() )
    > {
    > System.out.println("Token "+cnt+" is <"+st.nextToken()+">");
    > cnt ++;
    > }
    >
    > st = new StringTokenizer(hexString," ", true);
    > System.out.println("<"+hexString+"> w/delimits
    > tokens="+st.countTokens());
    > cnt = 1;
    > while ( st.hasMoreElements() )
    > {
    > System.out.println("Token "+cnt+" is <"+st.nextToken()+">");
    > cnt ++;
    > }
    > }
    > }
    >
    > Dave Rathnow <> wrote in message
    > news:LHqLa.41062$...
    > > I have a text string of hex values separated by
    > > whitespaces and I would like to read them using a
    > > StreamTokenizer. For example:
    > >
    > > String hexString = "0b ab ff 33 56"
    > >
    > > I've been trying to figure out how to do it but haven't
    > > had any luck. Can someone tell me how I setup a StreamTokenizer
    > > to give me each hex value? That is, "0b" then "ab" then "ff"
    > > etc.
    > >
    > > Thanks,
    > > Dave.
    > >
    > > P.S. I know I can do this with a StringTokenizer but I don't

    necessarily
    > > have my data in a String always.
    > >
    > >

    >
    >
     
    Dave Rathnow, Jun 30, 2003
    #2
    1. Advertising

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. John C. Bollinger

    Re: How does StreamTokenizer work

    John C. Bollinger, Jun 30, 2003, in forum: Java
    Replies:
    0
    Views:
    879
    John C. Bollinger
    Jun 30, 2003
  2. Sudsy

    Re: StreamTokenizer

    Sudsy, Jul 24, 2003, in forum: Java
    Replies:
    2
    Views:
    525
    Sudsy
    Aug 2, 2003
  3. Ian deSouza

    Re: StreamTokenizer

    Ian deSouza, Aug 1, 2003, in forum: Java
    Replies:
    0
    Views:
    1,579
    Ian deSouza
    Aug 1, 2003
  4. Lordy
    Replies:
    1
    Views:
    390
    Dale King
    Jun 11, 2006
  5. Replies:
    7
    Views:
    653
    John B. Matthews
    Sep 21, 2008
Loading...

Share This Page