• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Please help.... Read data in between

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Tiger,
It is so nice to hear from you again. Thanks for the trouble of your source code. Can I ask you another question again?
My question is how do I read the text data between two characters or two String, for example:
@HelloWorld@
test_HelloWorld_test
The data I wanted is of course the text "HelloWorld", but how can I do it? StringTokenizer class cannot do this kind of stuff.
Can you please kindly advise me on this?
Warmest regards,
Franco
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Huang
Why won't the StringTokenizer work?

If it is possible for the tokens to be part of the string then you're right it wont work but then the only way to get what you need is to know the postions of the tokens and then pull a subsring from the original.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This looks like a fairly standard templating problem to me. I guess you have these sort of token groups scattered at random throughout a file or stream, and waht to substitute different values for different tokens.
You can use StringTokenizer, but you need to keep track of whether you are "inside" or "outside" a token, even in tricky cases like "xx@name1@@name2@yy". The answer is to note that StringTokenizer has an alternative constructor which takes an extra parameter indicating whether to return the separators as well as the separated text:
StringTokenizer(String s, String delim, boolean returnDelims)
If you use this constructor, with the extra parameter set to true, you can do something like:

Has this helped ?
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another strategy I'd probably consider using would involve regular expressions (java.util.regex).
 
Huang Qingyan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I mean is there any other alternatives rather than using StringTokenizer()?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dirk Schreckmann:
Another strategy I'd probably consider using would involve regular expressions (java.util.regex).

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic