DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    Posts
    12

    a problem with tokenizer

    Dear friends,

    the string tokenizer works with me well in the begining but how can i set the tokenizer to start processing another part if the code. see the code below :


    String string = "Mike can not drive ";
    .

    System.out.println("\nthe token is :\n") ;

    StringTokenizer stok = new StringTokenizer(string);
    while (stok.hasMoreTokens())
    {
    System.out.println(stok.nextToken());

    }


    queue qu = new queue(stok.nextToken().length());




    The problem is just with the last code. it seems that no tokens has been read. therfore, is there any method that read the tokens from the begining.


    thanks

  2. #2
    Join Date
    Mar 2003
    Posts
    834
    You shouldn't really be surprised that there are no tokens left - you've just exited a loop who's exit condition was that there must be no tokens left!

    As I see it, you have two choices:

    1. Store the number of tokens in the StringTokenizer before you start to iterate over them:
    Code:
      ...
      int size = stok.countTokens();
      while (stok.hasMoreTokens()) {
        System.out.println(stok.nextToken());
      }
      queue qu = new queue(size);
    2. If you're going to be doing more tokenizing, you can just create a new StringTokenizer object:
    Code:
      ...
      while (stok.hasMoreTokens()) {
        System.out.println(stok.nextToken());
      }
      stok = new StringTokenizer(string);
      queue qu = new queue(stok.countTokens());
    ArchAngel.
    O:-)

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
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links