![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jul 2005
Posts: 73
Rep Power: 4
![]() |
explode() and aborting
is there a Java equivilent to the PHP explode() function?
also a method to abort the application? sorry if the answer is obvious, I am just really experienced in PHP but a noob at Java. :o Last edited by theguy0000; Dec 20th, 2005 at 7:49 PM. Reason: typo |
|
|
|
|
|
#2 |
|
Expert Programmer
|
exit(0); will abort the application.
The equivalent of the PHP explode(str) function in Java is str.split(regexp) which will return a String[] containing the separated pieces. Here is an example: String str = "one two three";
String[] result = str.split(" ");Because split() takes a regular expression as its argument some characters, like . | ? * + will cause problems. To prevent this you can escape them with a double backslash (\\). For example, str.split(".") will cause problems if you don't know that in regular expression terms "." represents any single character--so str.split("a.b") would separate the string at any three characters beginning with a and ending with b. To prevent this behavior in order to simply split the string at each period, you would use str.split("\\."). Last edited by titaniumdecoy; Dec 21st, 2005 at 12:48 AM. |
|
|
|
|
|
#3 |
|
Professional Programmer
|
You could also use a StringTokenizer to get similar results.
|
|
|
|
|
|
#4 |
|
Programmer
Join Date: Jul 2005
Posts: 73
Rep Power: 4
![]() |
perfect, exactly what I needed.
Thanks! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|