| View previous topic :: View next topic |
| Author |
Message |
Masamunexiii Guest
|
Posted: Thu Aug 11, 2005 5:10 am Post subject: Strings |
|
|
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?
|
|
| Back to top |
|
 |
Tonton Guest
|
Posted: Thu Aug 11, 2005 5:26 am Post subject: Re: Strings |
|
|
"Masamunexiii"
| Quote: | 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"
|
|
| Back to top |
|
 |
Hal Rosser Guest
|
Posted: Thu Aug 11, 2005 9:01 pm Post subject: Re: Strings |
|
|
"Masamunexiii" <jkamdar (AT) wideopenwest (DOT) com> wrote
| Quote: | 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.
|
|
| Back to top |
|
 |
Rivky Guest
|
Posted: Fri Aug 12, 2005 2:11 pm Post subject: Re: Strings |
|
|
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.
|
|
| Back to top |
|
 |
Hal Rosser Guest
|
Posted: Sat Aug 13, 2005 4:58 am Post subject: Re: Strings |
|
|
yeah - funny thing about java. more than one way to do it.
(Like Perl - or Microsoft dot-net- or Python - or PHP or <insert language here>)
"Rivky" <rasapir81 (AT) aol (DOT) com> wrote
| Quote: | 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.
|
|
|
| Back to top |
|
 |
|