SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: StringTokenizer

  1. #1
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    StringTokenizer

    i save this whole thing as a string.....
    Senior Project Manager-1,Assistant Manager-1,Chainmen-2,Clerk Of Work-1
    Asistant Manager-1,Chainmen-2,Clerk Of Work-1

    how do i know that this is end of string.....and what is the way that i need to save different number of data in the next string....
    for example i have this 2 data......i using StringTokenizer to separate it and how do i want to get one by one.......because every line of data it have different total of the employee........how do i check whether it is end of string......

    Thanks

  2. #2
    SitePoint Wizard silver trophy rushiku's Avatar
    Join Date
    Dec 2003
    Location
    A van down by the river
    Posts
    2,056
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Code:
    String string = "a,b,c";
    StringTokenizer tokens = new StringTokenizer( string, "," );
    while( tokens.hasMoreTokens() ) {
      System.out.println( tokens.nextToken() );
    }
    output:
    a
    b
    c
    The above code will tokenize and process a String containing 1 token, or 100,000 tokens - it doesn't matter how many there are. You'll know that there are no more tokens when the while fails.

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    check out the 'split' function. It has replaced StringTokenizer and is much easier to deal with.


Bookmarks

Posting Permissions

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