How do you break apart strings? For example the user type in John, Doe
E. and you want put John in one variable, Doe in another and E in the
third? I looked through any java books i found and it did not mention
this?
Tonton - 11 Aug 2005 06:26 GMT
"Masamunexiii"
> How do you break apart strings? For example the user type in John, Doe
> E. and you want put John in one variable, Doe in another and E in the
> third? I looked through any java books i found and it did not mention
> this?
You might find a neat solution using String[] String.split (String regex)
You might need to learn things about "regular-expressions"
Hal Rosser - 11 Aug 2005 22:01 GMT
> How do you break apart strings? For example the user type in John, Doe
> E. and you want put John in one variable, Doe in another and E in the
> third? I looked through any java books i found and it did not mention
> this?
Look at the split method of the String class - and also take a look at the
StringTokenizer class.
Rivky - 12 Aug 2005 15:11 GMT
You should also look at the String substing method. You can do
string.indexOf(" "); to find the index of the delimiter (maybe a space
in this case?) and the use the substring methid to grab data you want.
Hal Rosser - 13 Aug 2005 05:58 GMT
yeah - funny thing about java. more than one way to do it.
(Like Perl - or M$ dot-net- or Python - or PHP or <insert language here>)
> You should also look at the String substing method. You can do
> string.indexOf(" "); to find the index of the delimiter (maybe a space
> in this case?) and the use the substring methid to grab data you want.