StringUtils the methods involved in the Help class

Source: Internet
Author: User

/*1. String starts with prefix */
Stringutils.startswith ("Sssdf", "");//The result is: true
Stringutils.startswith ("Sssdf", "");//The result is: true
Stringutils.startswith ("Sssdf", "s");//The result is: true
Stringutils.startswith ("Sssdf", "SS");//The result is: true
Stringutils.startswith ("Sssdf", "SSS");//The result is: true
Stringutils.startswith ("Sssdf", "SSSDF");//The result is: true
Stringutils.startswith ("Sssdf", "f");//The result is: false
Stringutils.startswith ("Sssdf", "SSSDF");//The result is: true

/*2. String starting with prefix, case-insensitive */
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: false
Stringutils.startswithany ("Aabcde", newstring[]{"G", "a"});//The result is: true

/*4. String ends with suffix */
Stringutils.endswith ("Aabcde", "D");//The result is: false
Stringutils.endswith ("Aabcde", "E");//The result is: false
Stringutils.endswithignorecase ("", "");//The result is: false

/*5. Replace string: Replace the searchstring in text with Replacement,max is the maximum number of replacements, the default is to replace all */
Stringutils.replaceonce ("Sshhhss", "SS", "P");//Replace only one time-the result is: PHHHSS
Stringutils.replace ("SSHHHS", "SS", "P");//Replace All---> results are: PHHHS
Stringutils.replace ("Sshhhsshss", "ss", "7777", 2);//max: Maximum number of replacements-and results: 7777HHH7777HSS
Stringutils.replacechars ("SSHHHS", "SS", "P");//Replace all characters, as opposed to replace---> results are: pphhhp instead of PPHHHS

/*6. Replace by array, position to match, array length equal; not found the difference between the Replaceeach and replaceeachrepeatedly below.
Stringutils.replaceeach ("www.baidu.com", newstring[]{"Baidu", "com"},newstring[]{"taobao", "NET"});// The result is: www.taobao.net
Stringutils.replaceeach ("www.baidu,baidu.com", newstring[]{"Baidu", "com"},newstring[]{"taobao", "NET"});// The result is: www.taobao,taobao.net
stringutils.replaceeachrepeatedly ("www.baidu.com", newstring[]{"Baidu", "com"},newstring[]{"taobao", "NET"});// The result is: www.taobao.net

/*7. Compare two strings for equality, or equal if two are both NULL */
Stringutils.equals ("", "");//The result is true
Stringutils.equals (null,null);//result is true
Stringutils.equals ("", null);//result is False
Stringutils.equals (NULL, "");//result is False
Stringutils.equalsignorecase ("ss", "SS");//Case-insensitive--the result is true


/*8. Returns the position of the first occurrence of the SearchChar in the string, or returns if SearchChar does not appear in the string -1*/
Stringutils.indexof ("SDFSFSFDSF", "4");/* The result is -1*/
Stringutils.indexof ("SDFSFSFDSF", "f");/* The result is 2*/

Finds the last index in a string that appears in SearchChar */
Stringutils.lastindexof ("Afkyk", "K");//The result is 4
Stringutils.lastindexof ("Afkyk", "");//The result is 1

/*9. Find out where the character array Searchars first appears in the string */
Stringutils.indexofany ("Sdsfhhl0", "f");//The result is 3
Stringutils.indexofany ("Sdsfhhl0", newstring[]{"F", "0"});//result is 3
Stringutils.indexofany ("Sdsfhhl0", newstring[]{"T", "J"});//result is-1
Stringutils.indexofany ("Sdsfhhl0", newstring[]{"T", "J", ""});//result is 3
Stringutils.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 in, return-1
**/
Stringutils.indexofanybut ("Sdsfhhl0", "H");//The result is 0
Stringutils.indexofanybut ("Sdsfhhl0", "s");//result is 1
Stringutils.indexofanybut ("AA", "AA");//The result is-1

/*11. Statistics parameter 1 and parameter 2 the number of characters in the beginning of the first part */
Stringutils.indexofdifference ("SDSFDSF", "s");//result is 1
Stringutils.indexofdifference (newstring[]{"SDSFDSF", "s"});//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, ah ah");//The result is: Ah Ah

/*13. Lookup, case insensitive, no return -1*/found
Stringutils.indexofignorecase ("AFABBSSDD", "f");//return 1
Stringutils.indexofignorecase ("AFABBSSDD", "F", 2);//find from the specified position, case-insensitive--return-1
Stringutils.indexofignorecase ("AFABBSSDD", "F", 1);//return 1
Stringutils.lastindexofignorecase ("," "");
Stringutils.lastindexofignorecase ("", "", 2);

/*14. Intercepting a string at a specified location */
Stringutils.substring ("Dskabcee", 3);
/* The result is: abcee*/

Stringutils.substring ("Dskabcee", 3,5);
/* The result is: ab*/

/*15. Intercepting the contents of a 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 characters in the middle of parameter 2 and parameter 3 */
Stringutils.substringbetween ("Dskeabcedeh", "DS");
/* 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, can be set to get the length of the array, but generally do not set, this will conflict * *
Stringutils.split ("y5y,4454,545");//The default is by pressing, to split
Stringutils.split ("Aaaa#sss", "#");
/* The result is: [aaaa,sss]*/

Stringutils.split ("aaaa#sss#", "#", 2);

/*2. Splitting a string by a different type */
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. Ditto */
Stringutils.splitpreservealltokens ("");
Stringutils.splitpreservealltokens ("," "");
Stringutils.splitpreservealltokens ("", "", 3);

StringUtils the methods involved in the Help class

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.