View Full Version : java equivalent to php explode
Bobbo171
05-04-2005, 04:49 AM
What function in java is equivalent to the php explode function?
suryad
05-04-2005, 07:04 PM
I am gonna go ahead and assume you are working with server-side programming in JAva maybe? Are you using Servlets or JSPs? I worked with Servlets before and learning JSPs right now so I might be able to help if you could describe the functionality of explde in PHP.
suryad
05-04-2005, 07:05 PM
Hey I just did a simple google search and found maybe what you are looking for would be the StringTokenizer class or the split method in the String class. That would be my suggestion if I am not waaaaaaaaaaaaay off of what you are asking. CHeers!
shmoove
05-04-2005, 07:22 PM
Yup, String.split() will probably do (it doesn't have the limit optional parameter). (http://www.rgagnon.com/javadetails/java-0438.html)
Java Tip: You need to do something with strings, look for classes that have "string" in their name.
shmoove
String str = "Madrid,Paris,London";
String[] tokens = str.split(",")
-------------------------------------
tokens[0] = "Madrid";
tokens[1] = "Paris";
tokens[2] = "London";
-------------------------------------
deathcorvette
06-15-2010, 12:44 AM
The problem with String.split() is that it uses a greedy regex match, so if some of your tokens are empty strings, it will drop them. If you want to preserve empty strings, use this method:
StringUtils.splitPreserveAllTokens(String str, char separatorChar)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.