Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Split a string into array by delimiter string (similar to php: explode())
- * This this a supplement for the missing J2SE String.Split() in J2ME
- * @param s The input string.
- * @param delimiter The boundary string.
- * @return Returns an array of strings created by splitting the string parameter on boundaries formed by the delimiter
- */
- public static String[] split(String delimiter, String s){
- Vector v = new Vector();
- final int LEN = s.length();
- int start = 0;
- int stop = 0;
- while(start < LEN && start != -1){
- stop = s.indexOf(delimiter, start);
- if(stop == -1){
- stop = LEN;
- }
- v.addElement(s.substring(start, stop));
- start = stop + 1;
- if(stop < LEN){
- stop = s.indexOf(delimiter, start);
- }else{
- stop = LEN;
- }
- }
- String[] strings = new String[v.size()];
- v.copyInto(strings);
- return strings;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement