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

text parser

P: n/a
Hi,

i'm a newbie at java and have a question for beginners.
So i'm try to create a type of parser for a input-string. i take a
StringTokenizer to cut the Sting into token. But i want, that the
seperator belongs to the token and not to the next token. is there a
chance to do this, or is there a better way to spilt a Strong?

Thanks,
Rene
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
SPG
In the constructor of the tokeniser, you can speify if the delimiters become
tokens or not.
If all you want to do is split the string at each token, then use this
feature. If you are wanting the delimiter ragged onto the end of each token,
simply append it..

//Chop the string then put it back together!!!
StringBuffer buf = new StringBuffer();
StringTokenizer tok = new StringTokenizer("My|Token|String","|",false);
while(tok.hasMoreTokens()){
buf.append(tok.nextToken()).append("|");
}
System.out.println(tok.toString());

HTH

Steve
"Rene" <re**********@gmx.at> wrote in message
news:c2**************************@posting.google.c om...
Hi,

i'm a newbie at java and have a question for beginners.
So i'm try to create a type of parser for a input-string. i take a
StringTokenizer to cut the Sting into token. But i want, that the
seperator belongs to the token and not to the next token. is there a
chance to do this, or is there a better way to spilt a Strong?

Thanks,
Rene

Jul 17 '05 #2

P: n/a
> If all you want to do is split the string at each token, then use this
feature. If you are wanting the delimiter ragged onto the end of each token,
simply append it.. StringTokenizer tok = new StringTokenizer("My|Token|String","|",false);

^ (you
assume set of deleimeters to be just one character)
if you use StringTokenizer("String goes","delims") , the flag is false
by default (i think so) check docs

if you have set of delimeters with multiple characters, this would not
work.
i suggest write your own logic for parsing (if you have multiple
characters as delimeters)

regards
amey
Jul 17 '05 #3

P: n/a
am*****@yahoo.com (Amey Samant) wrote in message news:<66**************************@posting.google. com>...
If all you want to do is split the string at each token, then use this
feature. If you are wanting the delimiter ragged onto the end of each token,
simply append it..

StringTokenizer tok = new StringTokenizer("My|Token|String","|",false);

^ (you
assume set of deleimeters to be just one character)
if you use StringTokenizer("String goes","delims") , the flag is false
by default (i think so) check docs

if you have set of delimeters with multiple characters, this would not
work.
i suggest write your own logic for parsing (if you have multiple
characters as delimeters)

regards
amey


Hi,
thanks for your response!

I wanted to write my own logic of parsing, but i just abortive to
write my own logic! So i started to work with the Tokenizer. Maybe
some of you can give me a direction how i can do it. I wanted to make
a state machine, but as i already said i just faild.

Thanks,
Rene
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.