By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,541 Members | 1,106 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,541 IT Pros & Developers. It's quick & easy.

StringTokenizer question

P: n/a
Hi,

I'm having a little problem with the string tokenizer. For example, I got
this data string :
"0#0#0#0####0#0#0#.. and so on....."
How obvious, the # char will be the delimiter. But as you can see, at some
points there are two or more brackets pasted together. I want to let the
program return an empty string but the tokenizer just passes these brackets.
How to tell him he got to give the empty places as well?

Greetings,
Rick
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
One of the constructors for StringTokenizer has a boolean indicator
that tells it to return the delimiters as well. You could use that
contructor, then in your code loop, you can discard the delimiters,
but keep a flag so you can catch the condition where you get two
tokens in a row. In that case, you can process an empty string.

Bill Dennis
Jul 17 '05 #2

P: n/a
"Rick" <as******@hotmail.com> wrote in message news:<3f***********************@news.xs4all.nl>...
Hi,

I'm having a little problem with the string tokenizer. For example, I got
this data string :
"0#0#0#0####0#0#0#.. and so on....."
How obvious, the # char will be the delimiter. But as you can see, at some
points there are two or more brackets pasted together. I want to let the
program return an empty string but the tokenizer just passes these brackets.
How to tell him he got to give the empty places as well?

Greetings,
Rick

If you check in the documentation IIRC you'll find an extra parameter
which can be used to tell StringTokenizer to return the delimiters as
well as the tokens. Using this, plus a little extra work, it is
possible to figure out whether two delimiters have been passed in a
row, without any token in between, and treat this case as an empty
token.

One final thing to note is an issue if the string ends with a delimiter,
make sure you handle the implied empty token which 'follows' it. You
could do this by always appending a '#' (the delimiter) onto the end of
the tokenized string, so any implied empty token at the end of the string
could be processed without need to write special case code to detect it.
-FISH- ><>
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.