String Tokenizer Question


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: String Tokenizer Question

  1. #1
    Join Date
    May 2005
    Posts
    22

    String Tokenizer Question

    I know String Tokenizer is not the best way to solve this problem but i have to use it. Basically how do i setup the tokenizer to Extract all letters seperately.

    So given the string "xyz|[" i need to get the tokens:
    "x","y","z","|","[". Just wondering how to do this, and if i even can do this by just setting up a certain delimeter. Thanks.

  2. #2
    Join Date
    Dec 2006
    Location
    Kerala,India
    Posts
    51
    I think the best approach is using String.toCharArray() and u will get a Character array. or use charAt() instead of StringTokenizer.
    I don't understand why you are compelled to use StringTokenizer.

  3. #3
    Join Date
    May 2005
    Posts
    22
    yeah its just for an assignment, but im using charAt now, will ask prof why he tells us to use Tokenizer, thanks.

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    I don't understand it, either. There is no "delimiter" to tokenize the string ... not even white space. How can you "split" the string ... I think sudheerprem's and your approach with charAt is the best way to address this problem.

  5. #5
    Join Date
    Jan 2007
    Posts
    60
    I had to do something similar and I used the split method.

    I had to read all the lines from a file and count the number of occurrences of each letter.

    Code:
    while((textLine = MyFile.readLine()) !=null)
    
    		{
    
    			//Create an array to hold each of the words
    
    			//Remove any whitespace character (tab, new line, form feed, 
    
    			//end of line, carriage return)
    
    			String[] numWords = newLine.split("\\s");
    Hopefullt this will be of use to you as I found it a nightmare to do

  6. #6
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    AdRock: why wouldn't charAt do the same thing? Just iterate up the string, take charAt.

    The problem which p1kn1c is dealing with is the assignment calls for him to use StringTokenizer.

Similar Threads

  1. if statements
    By airrazor in forum Java
    Replies: 11
    Last Post: 11-06-2005, 10:18 AM
  2. to use or not to use SingleThreadModel?
    By ashiers in forum Java
    Replies: 0
    Last Post: 09-09-2005, 11:17 AM
  3. Input string was not in a correct format
    By mdengler in forum ASP.NET
    Replies: 0
    Last Post: 11-26-2002, 02:32 PM
  4. App Object
    By Rob Teixeira in forum .NET
    Replies: 15
    Last Post: 05-31-2002, 03:30 PM
  5. Trying to print a PDF File from VB
    By Kunal Sharma in forum VB Classic
    Replies: 2
    Last Post: 04-25-2000, 03:45 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center