Today, when using j2s, I found that there was no function in j2se to split strings, So I thought about it and designed the followingCodeWhich can be used to split a given string and send it for sharing.
Public String [] spilt (string original, string RegEx) {int startindex = 0; int lastindex = 0; lastindex = original. indexof (RegEx); vector v = new vector (); While (lastindex> 0) {v. addelement (original. substring (startindex, lastindex); startindex = lastindex + RegEx. length (); lastindex = original. indexof (RegEx, startindex); system. out. println ("startindex" + startindex);} v. addelement (original. substring (startindex); string [] STR = new string [v. size ()]; for (INT I = 0; I <v. size (); I ++) {system. out. println (v. elementat (I); STR [I] = (string) v. elementat (I);} return STR ;}
Parameters in the Code: original indicates the string to be split, and RegEx indicates the Separator
For example, spilt ("12 #2 #200000 ","#");
Result:
12
2
200000