/** * Split string, principle: detects the split string in the string, then takes the substring * @param original The string to be split * @paran regex Cut string * @return The string array generated after the split */ private static string[] Split (string original,string regex) { Take the starting position of the substring int startIndex = 0; //The result data into the vector first vector v = new vector (); //returns the result string array string[] str = NULL; //start position when the substring is stored int index = 0; //gets the position of the matched substring startindex = original.indexof (regex); //system.out.println ("0" + startIndex); //If the position of the starting string is less than the length of the string, the proof is not taken to the end of the string. The //-1 delegate takes the end while (StartIndex < Original.length () && StartIndex! =-1) { String temp = original.substring (Index,startindex); //Fetch substring v.addelement (temp); //Set the starting position of the substring index = startIndex + Regex.length (); //Get the location of the matching substring startindex = Original.indexof (Regex,startindex + regex.length ()); } //takes the end of the substring v.addelement (original.substring (index + 1-regex.length ())); //converts a vector object to an array of str = new string[v.size ()]; for (int i=0;i<v.size (); i++) { str[i] = (String) v.elementat (i); } //returns the generated array return str; } enhanced J2ME string capability--split string (source code) Author: Chenyue PK.: Http://blog.csdn.net/mailbomb
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.