Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Re: How does StreamTokenizer work (http://www.velocityreviews.com/forums/t123846-re-how-does-streamtokenizer-work.html)

D. Lane 06-29-2003 06:01 PM

Re: How does StreamTokenizer work
 
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 (laned@ix.netcom.com)
*/
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 <Dave.Rathnow@wrx-ca.com> wrote in message
news:LHqLa.41062$Mc4.5364903@news0.telusplanet.net ...
> 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 06-30-2003 06:26 AM

Re: How does StreamTokenizer work
 
Thanks,

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

Dave.

"D. Lane" <laned@ix.netcom.com> wrote in message
news:bdn9k9$klu$1@slb6.atl.mindspring.net...
> 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 (laned@ix.netcom.com)
> */
> 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 <Dave.Rathnow@wrx-ca.com> wrote in message
> news:LHqLa.41062$Mc4.5364903@news0.telusplanet.net ...
> > 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.
> >
> >

>
>





All times are GMT. The time now is 08:13 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57