• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Trying to capture and print specific data from tokenized string

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the quick response but unfortunately that wouldnt work..
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Robert, please UseCodeTags. You can use the edit button to add them to your post.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic