Advertisement
indraginanjar

String Split (J2ME)

Sep 8th, 2011
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1.     /**
  2.      * Split a string into array by delimiter string (similar to php: explode())
  3.      * This this a supplement for the missing J2SE String.Split() in J2ME
  4.      * @param s The input string.
  5.      * @param delimiter The boundary string.
  6.      * @return Returns an array of strings created by splitting the string parameter on boundaries formed by the delimiter
  7.      */
  8.     public static String[] split(String delimiter, String s){
  9.         Vector v = new Vector();
  10.         final int LEN = s.length();
  11.         int start = 0;
  12.         int stop = 0;
  13.         while(start < LEN && start != -1){
  14.             stop = s.indexOf(delimiter, start);
  15.             if(stop == -1){
  16.                 stop = LEN;
  17.             }
  18.             v.addElement(s.substring(start, stop));
  19.             start = stop + 1;
  20.             if(stop < LEN){
  21.                 stop = s.indexOf(delimiter, start);
  22.             }else{
  23.                 stop = LEN;
  24.             }
  25.         }
  26.         String[] strings = new String[v.size()];
  27.         v.copyInto(strings);
  28.         return strings;
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement