473,698 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4290
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|Stri ng","|",false );
while(tok.hasMo reTokens()){
buf.append(tok. nextToken()).ap pend("|");
}
System.out.prin tln(tok.toStrin g());

HTH

Steve
"Rene" <re**********@g mx.at> wrote in message
news:c2******** *************** ***@posting.goo gle.com...
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|Stri ng","|",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.c om (Amey Samant) wrote in message news:<66******* *************** ****@posting.go ogle.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|Stri ng","|",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
2672
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 instantiate parser, jvm wants to connect to X11 server. That means that I need X-server for simple html text parsing. Is there any workaround for this issue ? Any help appreciated.
0
2715
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 program is given below. The HTML is in a string to keep the example simple. The same problem appears with HTML in a file.
27
4996
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 any solid reasons to prefer text files over binary files files?
1
3652
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 trimmed the whitespaces while constructing the xml and there are no errors. however, if it is not trimmed prior to xml construction, and we placed the trim function in character method such that:
1
1808
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 in the field instead of the symbol it represents. The following example produces these results on Opera 8.5 and IE 6.0 I am expecting the same results whichever way I set the contents of "myText". Why, when choosing "function" does "&copy"...
2
1559
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 example of the text file: BORN ANTAL AXLAR = 220 VARMGÅNG
3
4097
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
2755
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 information from the text file! Can anyone enlighten me as to what I am doing wrong?
2
2664
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 use javascript or Jscript to work with the HTML code in the text string, in the same way that one works with XML code in a text string using the XML parser. If I was able to load the text string containing the HTML code succesfully, I would be...
13
4958
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 please tell me how do i go about it?
0
8676
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7732
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6522
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.