Stringutils. isempty usage

Source: Internet
Author: User

The operation object of the stringutils method is Java. lang. string-type objects are complementary to the string-type operation method provided by JDK, and are null safe (that is, if the input parameter string is null, nullpointerexception is not thrown, but corresponding processing is performed, for example, if the input is null, the return value is also null. You can view the source code ).

In addition to the constringutils, there are more than 130 methods in stringutils and they are all static, so we can call stringutils. XXX () in this way ()

The following describes some common methods:

1. Public static Boolean isempty (string Str)
Determines whether a string is null. If it is null, the standard is str = NULL or str. Length () = 0.
The following is an example of stringutils determining whether it is null:

Stringutils. isempty (null) = true
Stringutils. isempty ("") = true
Stringutils. isempty ("") = false // note that non-empty spaces are processed in stringutils.
Stringutils. isempty ("") = false
Stringutils. isempty ("Bob") = false
Stringutils. isempty ("Bob") = false

2. Public static Boolean isnotempty (string Str)
Determines whether a string is not null. It is equal! Isempty (string Str)
The following is an example:

Stringutils. isnotempty (null) = false
Stringutils. isnotempty ("") = false
Stringutils. isnotempty ("") = true
Stringutils. isnotempty ("") = true
Stringutils. isnotempty ("Bob") = true
Stringutils. isnotempty ("Bob") = true

3. Public static Boolean isblank (string Str)
Determines whether a string is null or has a length of 0 or is composed of whitespace.
The following is an example:
Stringutils. isblank (null) = true
Stringutils. isblank ("") = true
Stringutils. isblank ("") = true
Stringutils. isblank ("") = true
Stringutils. isblank ("\ t \ n \ f \ r") = true // For tabs, line breaks, page breaks, and carriage returns

Stringutils. isblank () // both are blank characters
Stringutils. isblank ("\ B") = false // "\ B" is the word boundary.
Stringutils. isblank ("Bob") = false
Stringutils. isblank ("Bob") = false

4. Public static Boolean isnotblank (string Str)
Determines whether a string is not empty and its length is not 0. It cannot be composed of whitespace. It is equal! Isblank (string Str)
The following is an example:

Stringutils. isnotblank (null) = false
Stringutils. isnotblank ("") = false
Stringutils. isnotblank ("") = false
Stringutils. isnotblank ("") = false
Stringutils. isnotblank ("\ t \ n \ f \ r") = false
Stringutils. isnotblank ("\ B") = true
Stringutils. isnotblank ("Bob") = true
Stringutils. isnotblank ("Bob") = true

5. Public static string trim (string Str)
Removes the control character (char <= 32) at both ends of the string. If the input is null, null is returned.
The following is an example:
Stringutils. Trim (null) = NULL
Stringutils. Trim ("") = ""
Stringutils. Trim ("") = ""
Stringutils. Trim ("\ B \ t \ n \ f \ r") = ""
Stringutils. Trim ("\ n \ TSS \ B") = "SS"
Stringutils. Trim ("d dd") = "d dd"
Stringutils. Trim ("DD") = "DD"
Stringutils. Trim ("DD") = "DD"

6. Public static string trimtonull (string Str)
Removes the control character (char <= 32) at both ends of the string. If it is null or "", null is returned.
The following is an example:
Stringutils. trimtonull (null) = NULL
Stringutils. trimtonull ("") = NULL
Stringutils. trimtonull ("") = NULL
Stringutils. trimtonull ("\ B \ t \ n \ f \ r") = NULL
Stringutils. trimtonull ("\ n \ TSS \ B") = "SS"
Stringutils. trimtonull ("d dd") = "d dd"
Stringutils. trimtonull ("DD") = "DD"
Stringutils. trimtonull ("DD") = "DD"

7. Public static string trimtoempty (string Str)
Removes the control character (char <= 32) at both ends of the string. If it is null or "", "" is returned ""
The following is an example:
Stringutils. trimtoempty (null) = ""
Stringutils. trimtoempty ("") = ""
Stringutils. trimtoempty ("") = ""
Stringutils. trimtoempty ("\ B \ t \ n \ f \ r") = ""
Stringutils. trimtoempty ("\ n \ TSS \ B") = "SS"
Stringutils. trimtoempty ("d dd") = "d dd"
Stringutils. trimtoempty ("DD") = "DD"
Stringutils. trimtoempty ("DD") = "DD"

8. Public static string strip (string Str)
Removes the whitespace at both ends of the string. If the input is null, null is returned.
The following is an example (note the difference with trim ):
Stringutils. Strip (null) = NULL
Stringutils. Strip ("") = ""
Stringutils. Strip ("") = ""
Stringutils. Strip ("\ B \ t \ n \ f \ r") = "\ B"
Stringutils. Strip ("\ n \ TSS \ B") = "SS \ B"
Stringutils. Strip ("d dd") = "d dd"
Stringutils. Strip ("DD") = "DD"
Stringutils. Strip ("DD") = "DD"

9. Public static string striptonull (string Str)
Removes the whitespace at both ends of the string. If it is null or "", null is returned.
The following is an example (note the difference between trimtonull () and trimtonull ):
Stringutils. striptonull (null) = NULL
Stringutils. striptonull ("") = NULL
Stringutils. striptonull ("") = NULL
Stringutils. striptonull ("\ B \ t \ n \ f \ r") = "\ B"
Stringutils. striptonull ("\ n \ TSS \ B") = "SS \ B"
Stringutils. striptonull ("d dd") = "d dd"
Stringutils. striptonull ("DD") = "DD"
Stringutils. striptonull ("DD") = "DD"

10. Public static string striptoempty (string Str)
Remove the whitespace at both ends of the string. If it is null or "", return ""
The following is an example (note the difference between trimtoempty () and trimtoempty ):
Stringutils. striptonull (null) = ""
Stringutils. striptonull ("") = ""
Stringutils. striptonull ("") = ""
Stringutils. striptonull ("\ B \ t \ n \ f \ r") = "\ B"
Stringutils. striptonull ("\ n \ TSS \ B") = "SS \ B"
Stringutils. striptonull ("d dd") = "d dd"
Stringutils. striptonull ("DD") = "DD"
Stringutils. striptonull ("DD") = "DD"

The following method only describes its functions:
11. Public static string strip (string STR, string stripchars)
Remove the characters at both ends of STR in stripchars.
If STR is null or equal to "", return it;
If stripchars is null or "", strip (string Str) is returned ).

12. Public static string stripstart (string STR, string stripchars)
Similar to '11', remove the character in stripchars at the front end of 'str.

13. Public static string stripend (string STR, string stripchars)
Similar to 11, remove the character at the end of STR in stripchars.

14. Public static string [] stripall (string [] STRs)
Strip (string Str) each string in the string array, and then return.
If STRs is null or the STRs length is 0, the STRs itself is returned.

15. Public static string [] stripall (string [] STRs, string stripchars)
Strip (string STR, string stripchars) each string in the string array, and then return.
If STRs is null or the STRs length is 0, the STRs itself is returned.

16. Public static Boolean equals (string str1, string str2)
Checks whether two strings are equal. If both strings are null, they are considered equal.

17. Public static Boolean inclusignorecase (string str1, string str2)
Compares the two strings to determine whether they are equal and case insensitive. If both strings are null, they are considered equal.

18. Public static int indexof (string STR, char searchchar)
Returns the position where the searchchar character first appears in the STR string.
If searchchar does not appear in STR,-1 is returned,
If STR is null or "",-1 is returned.

19. Public static int indexof (string STR, char searchchar, int startpos)
Returns the position of the first occurrence of the searchchar character in STR from startpos.
If searchchar does not appear in STR from startpos,-1 is returned,
If STR is null or "",-1 is returned.

20. Public static int indexof (string STR, string searchstr)
Returns the position where the string searchstr first appears in the string Str.
-1 is returned if STR is null or searchstr is null,
If searchstr is "" And STR is not null, 0 is returned,
If searchstr is not in STR,-1 is returned.

21. Public static int ordinalindexof (string STR, string searchstr, int ordinal)

Returns the position where the searchstr string appears at the Ordinal Time in the STR string.
If STR = NULL or searchstr = NULL or ordinal <= 0,-1 is returned.
Example (* represents any string ):
Stringutils. ordinalindexof (null, *, *) =-1
Stringutils. ordinalindexof (*, null, *) =-1
Stringutils. ordinalindexof ("", "", *) = 0
Stringutils. ordinalindexof ("aabaabaa", "A", 1) = 0
Stringutils. ordinalindexof ("aabaabaa", "A", 2) = 1
Stringutils. ordinalindexof ("aabaabaa", "B", 1) = 2
Stringutils. ordinalindexof ("aabaabaa", "B", 2) = 5
Stringutils. ordinalindexof ("aabaabaa", "AB", 1) = 1
Stringutils. ordinalindexof ("aabaabaa", "AB", 2) = 4
Stringutils. ordinalindexof ("aabaabaa", "BC", 1) =-1
Stringutils. ordinalindexof ("aabaabaa", "", 1) = 0
Stringutils. ordinalindexof ("aabaabaa", "", 2) = 0

22. Public static int indexof (string STR, string searchstr, int startpos)
Returns the position where the string searchstr first appears in the string STR from startpos.
Example (* represents any string ):
Stringutils. indexof (null, *, *) =-1
Stringutils. indexof (*, null, *) =-1
Stringutils. indexof ("", "", 0) = 0
Stringutils. indexof ("aabaabaa", "A", 0) = 0
Stringutils. indexof ("aabaabaa", "B", 0) = 2
Stringutils. indexof ("aabaabaa", "AB", 0) = 1
Stringutils. indexof ("aabaabaa", "B", 3) = 5
Stringutils. indexof ("aabaabaa", "B", 9) =-1
Stringutils. indexof ("aabaabaa", "B",-1) = 2
Stringutils. indexof ("aabaabaa", "", 2) = 2
Stringutils. indexof ("ABC", "", 9) = 3

23. Public static int lastindexof (string STR, char searchchar)
The basic principle is the same as 18

24. Public static int lastindexof (string STR, char searchchar, int startpos)
Basic Principles 19

25. Public static int lastindexof (string STR, string searchstr)
Basic principles: 20

26. Public static int lastindexof (string STR, string searchstr, int startpos)

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.