• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

StringTokenizer - why does it take [|] and [] as the same?

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm writing to code to tokenise this string

String theString = "123@star.com[|]lsep@mail.com,00887217904202[&]mmey@mail.com,00884457850456[&]00882131420000@star.com,[|]False[|][|]31/05/2004 08:48:43[|][|]"

StringTokenizer st = new StringTokenizer(theString, "[|]");

When I read it I get; (I'm counting the tokens at the start of the line)
8 123@satstar.com
7 lsep@mail.com,00887217904202
6 &
5 mmey@mail.com,00884457850456
4 &
3 00882131420000@satstar.com,
2 False
1 31/05/2004 08:48:43

The question is, why do the &'s next to 6 and 4 appear? And I am only expecting 6 tokens. Can anyone give some advice?

Thanks, Rachel
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

the "problem" is that the constructor does not work as you assume.

StringTokenizer st = new StringTokenizer(theString, "[|]");


The tokenizer does not use "[|]" as a delimiter, but each occurrence of any of the characters in the string, "[" or "|" or "]"

Bart
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I guess that makes sense...

Thanks!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic