473,382 Members | 1,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

text parser

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
3 4273
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
> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nebojsa Topolscak | last post by:
Hello, I wrote application which doesn't use graphic at all. One part of application needs Parser class from javax.swing.text.html.HTMLEditorKit. The ridiculous fact is when I try to...
0
by: Himanshu Garg | last post by:
Hello, I am using HTML::Parser to extract text from html pages from http://bbc.co.uk/urdu/ However the encoding of the input text seems to change to some unknown encoding in the output. The...
27
by: Eric | last post by:
Assume that disk space is not an issue (the files will be small < 5k in general for the purpose of storing preferences) Assume that transportation to another OS may never occur. Are there...
1
by: Eileene Cordoves | last post by:
hi i'm a newbie in xml and we're using org.apache.xerces.parsers.SAXParser. anyone know what the invalid characters in xml are? one of the value in the parsed xml is '<space><space>1', we...
1
by: google | last post by:
It would seem that when I assign an HTML entity to a form text input using "inline" javascript that it will display properly. But when trying to set it via a function call, the entity text shows...
2
by: Mattias Thuresson | last post by:
I want to convert a text based protocol into XML, using C#, how do I do that in the best maner ? Can I use XSLT in any way ? or do I have to make an parser that converts the file manually ? An...
3
by: matofarides | last post by:
Hello all! I was wondering whether there was a way, using any XML parser (preferably xerces), to create an XML file by reading, line by line a text file. Thank you, Marios Tofarides
9
by: Alex Buell | last post by:
I have a small text file which consist of the following data: ]] And the code I've written is as follows: ]] The trouble is, I can't work out why it goes into an infinite loop reading the...
2
by: David Virgil Hobbs | last post by:
Loading text strings containing HTML code into an HTML parser in a Javascript/Jscript I would like to know, how one would go about loading a text string containing HTML code, so as to be able to...
13
by: sonald | last post by:
Hi, Can anybody tell me how to change the text delimiter in FastCSV Parser ? By default the text delimiter is double quotes(") I want to change it to anything else... say a pipe (|).. can anyone...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.