[Tony]: If you use the CharacterSequence interface, you can perform your desired task without performing a copy of all elements Is "CharacterSequence" one of your custom classes, or did you mean
CharSequence? If it's the latter, I'd note that most current implementations of subSequence() from Sun's JDK's (in String, StringBuilder, StringBuffer) do the same copy Tony talks about avoiding. Some of the CharBuffer implementations may not. And of course one can make their own custom implementation of CharSequence. However this feels very very much like premature optimization, especially considering this post is in JiG Beginner.
Sanny: I like the regex solution suggested by AK Pillai. Though unfortunately, regular expressions are another thing non-obvious for beginners. Sanny, you may want to study the
Java tutorial for more info on regular expressions. (Or learn more from one of the several books out there, Friedl, Habibi...) Note that the String class has methods defined directly, which can streamline the code a bit from what AK showed:
Learning how regular expressions work takes some time, but I think it's time well spent since it gives you many flexible and pwoerful options fora problem like this.
[ March 13, 2006: Message edited by: Jim Yingst ]