• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trying to capture and print specific data from tokenized string

 
Robert Gaia
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick response but unfortunately that wouldnt work..
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert, please UseCodeTags. You can use the edit button to add them to your post.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic