Results 1 to 3 of 3
  1. #1
    miss.meli's Avatar
    miss.meli is offline Member
    Join Date
    Nov 2008
    Location
    Austin, TX
    Posts
    17
    Rep Power
    0

    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:

    Java 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

  2. #2
    miss.meli's Avatar
    miss.meli is offline Member
    Join Date
    Nov 2008
    Location
    Austin, TX
    Posts
    17
    Rep Power
    0

    Default

    Here's what I have:

    Java 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

  3. #3
    miss.meli's Avatar
    miss.meli is offline Member
    Join Date
    Nov 2008
    Location
    Austin, TX
    Posts
    17
    Rep Power
    0

    Default

    I got it. But for those who look at this and wonder what it was, the code turned out to be:

    Java Code:
    StringTokenizer st = new StringTokenizer(v, " .,?!:;()-1234567890\b\t\n\f\r\"\'\\");
    miss.meli (-.-)zzZZ

Similar Threads

  1. StringTokenizer in a Palindrome program
    By jeremyk in forum New To Java
    Replies: 10
    Last Post: 02-13-2010, 07:35 PM
  2. StringTokenizer
    By carderne in forum New To Java
    Replies: 1
    Last Post: 01-26-2008, 09:19 PM
  3. StringTokenizer
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-08-2007, 09:48 AM
  4. StringTokenizer
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-03-2007, 10:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •