/*1. String starting with prefix */stringutils.startswith ("sssdf", "");//Result: Truestringutils.startswith ("Sssdf", "");// The result is: Truestringutils.startswith ("Sssdf", "s");//The result is: Truestringutils.startswith ("Sssdf", "SS");// The result is: Truestringutils.startswith ("Sssdf", "SSS");//The result is: Truestringutils.startswith ("Sssdf", "SSSDF");// The result is: Truestringutils.startswith ("Sssdf", "f");//The result is: Falsestringutils.startswith ("Sssdf", "SSSDF");//The result is: true/*2. The string starts with prefix and is not case-sensitive */stringutils.startswithignorecase ("Sssdf", "SSSDF");//The result is: True/*3. String starts with the string in the array */ Stringutils.startswithany ("Aabcde", newstring[]{"G", "F"});//The result is: Falsestringutils.startswithany ("AABCDE", Newstring[]{"G", "a"});//The result is: True/*4. String ends with suffix */stringutils.endswith ("Aabcde", "D");// The result is: Falsestringutils.endswith ("Aabcde", "E");//The result is: Falsestringutils.endswithignorecase ("", "");//The result is: false/*5. Replacement string: Replace the text in the searchstring with Replacement,max is the maximum number of replacements, the default is to replace All */stringutils.replaceonce ("Sshhhss", "SS", "P");// Replace only once-the result is: Phhhssstringutils.replace ("SSHHHS", "SS", "P");//Replace All---> results are: phhhsstringutils.rePlace ("Sshhhsshss", "ss", "7777", 2);//max: Maximum number of substitutions and results: 7777hhh7777hssstringutils.replacechars ("SSHHHS", "SS", " P ");//Replace all characters, as opposed to replace---> The result is: PPHHHP instead of pphhhs/*6. Replace by array, position to match, array length equal; Temporarily did not find the following Replaceeach and replaceeachrepeatedly the difference between the */stringutils.replaceeach ("www.baidu.com", newstring[]{"Baidu", " com "},newstring[]{" taobao "," NET "});//The result is: Www.taobao.netStringUtils.replaceEach (" www.baidu,baidu.com ", newstring []{"Baidu", "com"},newstring[]{"taobao", "NET"});//The result is: www.taobao,taobao.netStringUtils.replaceEachRepeatedly (" Www.baidu.com ", newstring[]{" Baidu "," com "},newstring[]{" taobao "," NET "});//The result is: www.taobao.net/*7. Compares two strings for equality, If two are null, equal */stringutils.equals ("", "" ") is also considered;//The result is truestringutils.equals (null,null);// The result is truestringutils.equals ("", null);//The result is falsestringutils.equals (null, "");// The result is falsestringutils.equalsignorecase ("ss", "SS");//Case-insensitive-the result is true/*8. Returns the position of the first occurrence of the SearchChar in the string, If SearchChar does not appear in the string, it returns -1*/stringutils.indexof ("SDFSFSFDSF", "4");/* The result is -1*/stringutils.indexof ("SDFSFSFDSF", " F ");/* results are 2*///Finds the index */stringutils.lastindexof ("Afkyk", "K") of the last occurrence of SearchChar in the string;//The result is 4stringutils.lastindexof ("Afkyk", "");// The result is 1/*9. Find out where the character array Searchars first appeared in the string */stringutils.indexofany ("Sdsfhhl0", "f");//The result is 3stringutils.indexofany (" Sdsfhhl0 ", newstring[]{" F "," 0 "});//The result is 3stringutils.indexofany (" Sdsfhhl0 ", newstring[]{" T "," J "});// The result is -1stringutils.indexofany ("Sdsfhhl0", newstring[]{"T", "J", ""});//The result is 3stringutils.lastindexofany ("Afkyk", newstring[]{"Afkyk", "K"});//Find out where the character array Searchars last appeared in the string-the result is 5/*10. Find out where the first character in a string is not in the character array Searchars (starting at 0 bits) * If all is in, return -1**/stringutils.indexofanybut ("Sdsfhhl0", "H");//The result is 0stringutils.indexofanybut ("Sdsfhhl0", "s");// The result is 1stringutils.indexofanybut ("AA", "AA");//The result is -1/*11. The number of characters that are common to the beginning of the statistical parameter 1 and Parameter 2 is */stringutils.indexofdifference (" SDSFDSF "," s ");//The result is 1stringutils.indexofdifference (newstring[]{" SDSFDSF "," s "});//The result is 1/*12. Remove the string that is common to parameter 2 at the beginning of parameter 1 */ Stringutils.difference ("Irrigation and irrigation", "irrigation and irrigation");//The result is: Ah ah/*13. Find, case-insensitive, not found return -1*/stringutils.indexofignorecase (" AFABBSSDD "," f ");//Return 1stringutils.indexofignorecase("AFABBSSDD", "F", 2);//search from specified position, case-insensitive-return -1stringutils.indexofignorecase ("AFABBSSDD", "F", 1);// Return 1stringutils.lastindexofignorecase ("", ""); Stringutils.lastindexofignorecase ("", "", 2);/*14. Intercepts the string */stringutils.substring ("Dskabcee", 3) at the specified position;/* The result is: abcee*/ Stringutils.substring ("Dskabcee", 3,5);/* The result is: ab*//*15. Intercepts the content before the specified string */stringutils.substringbefore ("Dskeabcee", "E" );/* The result is: Dskeabce*/stringutils.substringbeforelast ("Dskeabcee", "E");//Always find the last specified string/* The result is: dskeabce*/ Stringutils.substringafter ("Dskeabcedeh", "");/* The result is: Dskeabcedeh*/stringutils.substringafterlast ("Dskeabcedeh", " ");/* The result is: *//*16. Intercept the character */stringutils.substringbetween (" Dskeabcedeh "," DS ") in the middle of parameter 2 and parameter 3;/* The result is: null*/ Stringutils.substringbetween ("Dskeabcedeh", "DS", "E");/* The result is: K*/stringutils.substringsbetween ("Dskeabcedeh", "DS" , "E");//Returns the string in the middle of parameter 2 and parameter 3 as an array * * The result is: [keabce]*//*1. Split string, you can set the length of the array, but generally do not set, this will occur conflict */stringutils.split ("y5y, 4454,545 ");//The default is to split Stringutils.split (" Aaaa#sss "," # ");/* The result is: [Aaaa,sss]*/stringutils.split (" aaaa#sss# "," # ", 2) ;/*2. By Different typesSplit string */stringutils.splitbycharactertype ("aa3444 Zhang San Bcss");/* The result is: [aa,3444, Zhang San, a,b,css,b]*/ Stringutils.splitbycharactertypecamelcase ("");/* The result is: [aa,3444, Zhang San, a,bcss,b]*//*3. Split string, "" will not be ignored, you can set the array length of the split string */ Stringutils.splitbywholeseparator ("aaaa#sss#", "#");//"" will not be ignored//The result is: [aaaa,sss,]stringutils.split result is: [aaaa,sss]*/ Stringutils.splitbywholeseparator ("Aaaa#sss#ggg", "#");///* the result is: [aaaa,sss,ggg]*/ Stringutils.splitbywholeseparator ("Aaaa#sss#ggg", "");//split by Space//The result is: [aaaa#,sss#ggg]*/ Stringutils.splitbywholeseparator ("aaaa#sss#", "#", 2);//2 sets the maximum length of the returned array/* The result is: [Aaaa,sss#]*//*4. Split string, "" will not be ignored, You can set the array length of the split string */stringutils.splitbywholeseparatorpreservealltokens ("Sddssfsfasfsaf", null);/* The result is: [SDDSSF, Sfasfsaf,]*/stringutils.splitbywholeseparatorpreservealltokens ("Sddssfsfasfsaf", "");/* The result is: [sddssf,sfasfsaf,]*/ /*5. Ibid. */stringutils.splitpreservealltokens (""); Stringutils.splitpreservealltokens ("," ""); Stringutils.splitpreservealltokens ("", "", 3);
This article is from the "CEO's Road" blog, make sure to keep this source http://zhaohaibo.blog.51cto.com/7808533/1590054
StringUtils Tool Class Usage