This week's book giveaways are in the iOS and Features new in Java 8 forums. We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line! See this thread and this one for details.
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
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.
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: