Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

StringTokenizer

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my project, i came across the following situation:

I want to parse the string like "Value!first!second!!third"
When i use StringTokenizer class with ! as delimiter, it is returning the following tokens:
value
first
second
third
But i want the empty string also between ! and !
I am not getting that bcoz the string tokenizer advances the pointer after it founds the delimiter...

Could some one help me? Waiting for your valuable answers...
Thanx a lot...
 
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is why the StringTokenizer constructor has an optional third parameter. By default, StringTokenizer doesn't return separators, but you can get it to return them, and take not of whether the preceding field was empty:
here's a slightly modified example from my own code:

I hope this helps.
 
Uma Viswanathan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx a lot...
I had found out the solution in the following two ways:
Method1:

Method2:

[ May 30, 2002: Message edited by: Dirk Schreckmann ]
 
Uma Viswanathan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, i had typed the second method wrongly:

i.e, instead of storing "", i am storing "< Empty >"
[ May 30, 2002: Message edited by: Dirk Schreckmann ]
 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic