![]() |
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. > > |
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.