| Author |
Please help.... Read data in between
|
Huang Qingyan
Greenhorn
Joined: Jan 18, 2002
Posts: 23
|
|
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
|
 |
Dave Vick
Ranch Hand
Joined: May 10, 2001
Posts: 3244
|
|
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.
|
Dave
|
 |
Frank Carver
Sheriff
Joined: Jan 07, 1999
Posts: 6913
|
|
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 ?
|
A Convergent Visionary ~ Frank's Punchbarrel Blog ~ LinkedIn profile
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
|
Another strategy I'd probably consider using would involve regular expressions (java.util.regex).
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
Huang Qingyan
Greenhorn
Joined: Jan 18, 2002
Posts: 23
|
|
|
What I mean is there any other alternatives rather than using StringTokenizer()?
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
Originally posted by Dirk Schreckmann: Another strategy I'd probably consider using would involve regular expressions (java.util.regex).
|
 |
 |
|
|
subject: Please help.... Read data in between
|
|
|