If you glance at the documentation for String.split, you will see it
uses Regular Expressions. If you look these up (e.g. under
java.util.regex.Pattern - I do advise looking at these: invaluable),
you can see all the special characters you can use - very powerful
stuff!!
But yes, you are right that * is a special character, and you need to
use something like "\*" to do the job.
If you don't know the delimiter at compile time, use Pattern.quote() to
convert a delimiter string to one that can be used safely with split(),
Tarry Waterson - 01 Apr 2005 10:41 GMT
Thanks for that.
Should do the trick
Cheers
Tarry
> If you glance at the documentation for String.split, you will see it
> uses Regular Expressions. If you look these up (e.g. under
[quoted text clipped - 6 lines]
> If you don't know the delimiter at compile time, use Pattern.quote() to
> convert a delimiter string to one that can be used safely with split(),
Tarry Waterson - 01 Apr 2005 16:51 GMT
Sanjay
"\*" does not work. Reports illegal escape character. I also had a look at
using Pattern.quote() but this method is not included in my Pattern package
(I am using SDK 1.4.2_04).
Any other suggestions?
> If you glance at the documentation for String.split, you will see it
> uses Regular Expressions. If you look these up (e.g. under
[quoted text clipped - 6 lines]
> If you don't know the delimiter at compile time, use Pattern.quote() to
> convert a delimiter string to one that can be used safely with split(),
sanjay manohar - 04 Apr 2005 05:01 GMT
Ah! Sorry, I forgot that the parser will also look for escape
sequences. To get a '\' character in a string, you need to use "\\".
So try String delimeter = "\\*";
This string will actually contain the two characters '\' and '*'
Crazy system, I'm glad I didnt invent it
Tarry Waterson - 09 Apr 2005 12:51 GMT
Thanks Sanjay
That is a winner.
Tarry
> Ah! Sorry, I forgot that the parser will also look for escape
> sequences. To get a '\' character in a string, you need to use "\\".
>
> So try String delimeter = "\\*";
> This string will actually contain the two characters '\' and '*'
> Crazy system, I'm glad I didnt invent it