• Post Reply Bookmark Topic Watch Topic
  • New Topic

StringTokenizer question  RSS feed

 
Jake Lovowitz
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am in the middle of a project in which I have been heavily relying on the StringTokenizer function. However, I have come across an area where I need to be able to scan the next token w/o removing it from the StringTokenizer. Alternatively, I could just as well use a function that can reinsert a token into the head of the StringTokenizer. Does anyone know how to do either function? I looked on Sun's java site, but there was no help there. Thanks so much.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a similar approach, change from StringTokenizer to String.split() or if you're JDK < 1.4 read all the tokens into an array. That will give you an array you can step through and back up if you change your mind.

For a completely different approach, PushbackReader will let you read a smallish number of bytes (say one or two tokens) and put them back. You'd probably want your own readToken() that knows how to read one token and stop. Let me know if that made sense in your context.
[ July 03, 2004: Message edited by: Stan James ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!