Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 20th, 2005, 7:35 PM   #1
theguy0000
Programmer
 
Join Date: Jul 2005
Posts: 73
Rep Power: 4 theguy0000 is on a distinguished road
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
theguy0000 is offline   Reply With Quote
Old Dec 21st, 2005, 12:38 AM   #2
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 856
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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(" ");
At the end result will contain the array "one", "two", "three".

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.
titaniumdecoy is offline   Reply With Quote
Old Dec 21st, 2005, 3:01 AM   #3
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 312
Rep Power: 3 andro is on a distinguished road
Send a message via AIM to andro
You could also use a StringTokenizer to get similar results.
andro is offline   Reply With Quote
Old Dec 21st, 2005, 9:53 AM   #4
theguy0000
Programmer
 
Join Date: Jul 2005
Posts: 73
Rep Power: 4 theguy0000 is on a distinguished road
perfect, exactly what I needed.

Thanks!
theguy0000 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:31 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC