Results 1 to 4 of 4
  1. #1
    kgkamaraj is offline Member
    Join Date
    Feb 2010
    Posts
    9
    Rep Power
    0

    Default Storing a string in StringTokenizer

    Hi,
    I am going to store a string in string tokenizer. But i am not getting the output what i think.

    For example :

    StringTokenizer st = new StringTokenizer("I born on 21.02.1995. So, now my age is 15.", ".");

    I will get output as :

    I born on 21
    02
    1995
    So, now my age is 15.

    But i want output as :

    I born on 21.02.1995.
    So, now my age is 15.

  2. #2
    x2robbie2x is offline Member
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    0

    Default

    I think you need a \ before every special character that's not special, like the periods in the date, just like in an output if you need to output " you would do System.out.println(" blah blah blah \" blah \" blah");
    Just a suggestion, idk

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by kgkamaraj View Post
    Hi,
    I am going to store a string in string tokenizer. But i am not getting the output what i think.
    You really can't store a String with StringTokenizer as it has no capacity for storage, only for tokenizing.

    For example :
    StringTokenizer st = new StringTokenizer("I born on 21.02.1995. So, now my age is 15.", ".");
    I will get output as :

    I born on 21
    02
    1995
    So, now my age is 15.

    But i want output as :

    I born on 21.02.1995.
    So, now my age is 15.
    Your output is as expected given your delimiter. If you want it to be different, I would recommend use of String#split(String regex) with an appropriate regex
    Last edited by Fubarable; 02-12-2010 at 02:02 PM.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by x2robbie2x View Post
    I think you need a \ before every special character that's not special, like the periods in the date, just like in an output if you need to output " you would do System.out.println(" blah blah blah \" blah \" blah");
    Just a suggestion, idk
    That's only for regex Strings such as used by String#split(String regex). On review of the StringTokenizer API, you'll see that it does not use regex and so there's no need to use \ before the period.

Similar Threads

  1. storing a string in an array
    By tiyani in forum New To Java
    Replies: 3
    Last Post: 08-12-2009, 07:25 PM
  2. Help with StringTokenizer!
    By ookie833 in forum New To Java
    Replies: 13
    Last Post: 12-14-2008, 04:09 PM
  3. StringTokenizer
    By carderne in forum New To Java
    Replies: 1
    Last Post: 01-26-2008, 08:19 PM
  4. StringTokenizer
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-08-2007, 08:48 AM
  5. StringTokenizer
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-03-2007, 09: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
  •