problem splitting strings

hello all,

i have a string of the format similar to this:

anycharactergoeshere;;;;;

and i'm trying to split the string on semicolons with:

foo.split("(;)");

and i have tried numerous other regular expressions with numerous quantifiers but none will seem to split on just the first semicolon, instead it takes them all of them at once.....

ideally i would like to split them and the following in a String array after splitting

someArray[0] == "anycharactergoeshere;"

someArray[1] == ";;;;;"

where the number of semicolons is arbitrary. any help is appreciated.

[624 byte] By [BigCdaAnswer3a] at [2007-10-2 15:48:15]
# 1

If the problem is just as described then the substring and indexOf methods are all that you need to do.

There is no need for any complex parsing, regex or tokenizing here. Just build substrings from the IndexOf the first semicolon. Then you can get two strings and the number of semi-colons matters not.

BigCdaAnswer3a at 2007-7-13 15:49:48 > top of Java-index,Java Essentials,Java Programming...
# 2
The simple answer is: String[] parts = foo.split(";", 2);But it looks like you want to keep the semicolon, too. In that case, you could do this: String[] parts = foo.split("(?<=;)", 2);
uncle_alicea at 2007-7-13 15:49:48 > top of Java-index,Java Essentials,Java Programming...