GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Trying to capture and print specific data from tokenized string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trying to capture and print specific data from tokenized string" Watch "Trying to capture and print specific data from tokenized string" New topic
Author

Trying to capture and print specific data from tokenized string

Robert Gaia
Greenhorn

Joined: Apr 29, 2010
Posts: 3
Hi All,
Im very new to java so please bare with me...

I utilized the string tokenizer to display the below tokens but need to only display or write
the data between 'New Member Information ' and ' 1. Reason for Submission ' . Can anyone assist?

StringTokenizer st = new StringTokenizer(HtmlTable_0_Text);
while (st.hasMoreTokens()) {
sErrorMsg = st.nextToken();
System.out.println(sErrorMsg);
filewrite(sErrorMsg);

New
Member
Information
Provider
Id
100389
not
valid.
1.
Reason
for
Submission
Venkata Krishn Rao Maddu
Greenhorn

Joined: Apr 02, 2008
Posts: 3
I dont know following will be the better choice or not but, I have tried in this way and it would give other numbers also if your input string contains numbers otherthan Id number.



use above method while iterating the string tokenizer


Robert Gaia
Greenhorn

Joined: Apr 29, 2010
Posts: 3
Thanks for the quick response but unfortunately that wouldnt work..
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39096
    
  23
Welcome to the Ranch

You realise StringTokenizer is regarded as legacy code? It tells you in the API link what you ought to use instead.
Google for JFlex and in its manual you will find instructions how to write a lexer forJava (I think it's an old version, but that doesn't matter). In that code or in the "simple example", you will find a regular expression for integers. You can probably find similar regular expressions elsewhere easily enough.
Go through the Java™ Tutorials and you will find a nice section about regular expressions.

That should help.
Robert Gaia
Greenhorn

Joined: Apr 29, 2010
Posts: 3
Howdy..
I was able to capture specific data from within a string from a text file using the tokenizer. Now Im stuck on how to pull the captured strings back together so its readable.. (not displayed line by line).
The output displays as:

The
Zip
field
is
required.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Robert, please UseCodeTags. You can use the edit button to add them to your post.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
GeeCON Prague 2014
 
subject: Trying to capture and print specific data from tokenized string