Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Alternative to StringTokenizer

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any alternative ( other than substring ) that can be used instead of StringTokenizer ???
Actually, I am facing a problem with StringTokenizer. If I have a string with a character '=' in it, then the following code results in false tokens :
StringTokenizer valToken = new StringTokenizer(val,"==>");
while(valToken.hasMoreTokens())
{
valno = valToken.nextToken();
valdate= valToken.nextToken();
}
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you only need to include a character once in the delim parameter of the StringTokenizer constructor(eg. StringTokenizer(val,"=>"). What does the String you are trying to tokenize contain?
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the exact delimitor? If "=" is your delimitor, only "=" should be put inside the constructor.
 
Bhushan Shete
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The delimiter is exactly the same as I have shown in my query / code. Actually, I have a string as follows :
abcdtest==>xyztest
Where, abcdtest is the value of one variable & xyztest, value of another variable. I concatenate these two variables along with the delimiter.
Now, if my variable contains abcd=test, then it becomes :
abcd=test==>xyztest
And here is where I get false tokens.
I am still trying to sort out this problem.
Anyways, Thanx for ur replies.
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's important to realize that StringTokenizer always delimits using a SINGLE character. The tokenizing string you send it is actually a LIST of characters that will function as tokens. If you want to use a multicharacter delimiter, such as "==>", string tokenizer will not work for you. So, you could do what I did, which is look at the java source for StringTokenizer, and design you own class that does what you want. It's actually much simpler than designing a multi-character tokenizer. I'd post my code, but I wrote it for work, and I'm under non-disclosure. It's not that hard, tho. Just implement the enumerator interface methods.
HTH
e
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See my reply here.
[This message has been edited by Jim Yingst (edited March 20, 2001).]
 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bhushan,
Read this article on Pitfall 2 to see how you can implement a work-around to this problem.
-Peter
 
Bhushan Shete
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx a lot to everyone. I have gone thru the source code (actual implementation of StringTokenizer provided by SUN.)
I am thru with it now.
Thanx a lot once again.
 
It wasn't my idea to go to some crazy nightclub in the middle of nowhere. I just wanted to stay home and cuddle with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic