Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-03-2008, 12:09 AM
miss.meli's Avatar
Member
 
Join Date: Nov 2008
Location: Austin, TX
Posts: 17
Rep Power: 0
miss.meli is on a distinguished road
Default [SOLVED] Questions about StringTokenizer
So I'm looking at this StringTokenizer and I understand how it works when you just put in a String. It gives you what's between the white space. But there's something else you can do with it. You can use delimiters which is where I'm a little confused on how to create this tokenizer. What I want to do is get the tokens from a String such as:

Code:
String s = "It's a nice day, don't you think?";
And I want to be able to print each token out like this...

It s a nice day don t you think

So basically the tokenizer not only skips the white space, it skips punctuation marks as well, which you send in to the tokenizer. How can I do that?

Btw, I can't put the link to the java doc of StringTokenizer on here yet, don't have enough posts lol silly...

Thanks
__________________
miss.meli (-.-)zzZZ
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-03-2008, 12:19 AM
miss.meli's Avatar
Member
 
Join Date: Nov 2008
Location: Austin, TX
Posts: 17
Rep Power: 0
miss.meli is on a distinguished road
Default
Here's what I have:

Code:
StringTokenizer st = new StringTokenizer(v, ".,?!:-1234567890");
But there's a problem now. I solved the problem of the tokenizer skipping over the punctuation and numbers I want, but now it no longer skips over white space. I tried putting a space in there, but if there are several spaces like "this is cool" then it will token like this this is cool which I don't want, I want it to skip all whitespace...How can I fix this?
__________________
miss.meli (-.-)zzZZ
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-03-2008, 09:26 AM
miss.meli's Avatar
Member
 
Join Date: Nov 2008
Location: Austin, TX
Posts: 17
Rep Power: 0
miss.meli is on a distinguished road
Default
I got it. But for those who look at this and wonder what it was, the code turned out to be:

Code:
StringTokenizer st = new StringTokenizer(v, " .,?!:;()-1234567890\b\t\n\f\r\"\'\\");
__________________
miss.meli (-.-)zzZZ
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
StringTokenizer in a Palindrome program jeremyk New To Java 10 02-13-2010 07:35 PM
StringTokenizer carderne New To Java 1 01-26-2008 09:19 PM
Performance Issues (StringTokenizer) JavaForums Java Blogs 0 11-29-2007 02:22 PM
StringTokenizer Java Tip Java Tips 0 11-08-2007 09:48 AM
StringTokenizer Java Tip Java Tips 0 11-03-2007 10:24 PM


All times are GMT +2. The time now is 05:58 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org