欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

String Utils 工具类介绍大全 isAnyEmpty isAnyBlank stripToNull 等,一篇文章找全所有答案!

程序员文章站 2022-06-16 10:41:45
StringUtils工具类介绍前言1.isEmpty()2.isNotEmpty()3.isAnyEmpty()4.isNoneEmpty()5.isBlank()6.isNotBlank()7.isAnyBlank()8.isNoneBlank()9.trim()10.trimToNull()11.trimToEmpty()12.strip()13.stripToNull()14.stripToEmpty()15.stripStart()16.stripEnd()17.stripAll()18.stri...

StringUtils工具类介绍


前言

不多逼逼,直接开始

1.isEmpty()

描述:null与空串是empty的判断依据。

* StringUtils.isEmpty(null) = true
* StringUtils.isEmpty("") = true
* StringUtils.isEmpty(" ") = false
* StringUtils.isEmpty("bob") = false

2.isNotEmpty()

描述:对isEmpty()取反

* StringUtils.isNotEmpty(null) = false
* StringUtils.isNotEmpty("") = false
* StringUtils.isNotEmpty(" ") = true
* StringUtils.isNotEmpty("bob") = true

3.isAnyEmpty()

描述:isAnyEmpty只要有一个字符串为empty,返回值就为true。

* StringUtils.isAnyEmpty(null) = true
* StringUtils.isAnyEmpty(null, "foo") = true
* StringUtils.isAnyEmpty("", "bar") = true
* StringUtils.isAnyEmpty("bob", "") = true
* StringUtils.isAnyEmpty("  bob  ", null) = true
* StringUtils.isAnyEmpty(" ", "bar") = false
* StringUtils.isAnyEmpty("foo", "bar") = false

4.isNoneEmpty()

描述:null与空串是empty的判断依据。

* StringUtils.isNoneEmpty(null) = false
* StringUtils.isNoneEmpty(null, "foo") = false
* StringUtils.isNoneEmpty("", "bar") = false
* StringUtils.isNoneEmpty("bob", "") = false
* StringUtils.isNoneEmpty("  bob  ", null) = false
* StringUtils.isNoneEmpty(" ", "bar") = true
* StringUtils.isNoneEmpty("foo", "bar") = true

5.isBlank()

描述:blank的判断依据是在empty的基础上添加一个空白符(即空格)。也就是说,null、空串、只包含空白符就是blank,isblank返回true。

* StringUtils.isBlank(null) = true
* StringUtils.isBlank("") = true
* StringUtils.isBlank(" ")  = true
* StringUtils.isBlank("bob") = false
* StringUtils.isBlank("  bob  ") = false

6.isNotBlank()

描述:是对isBlank()取反。

* StringUtils.isNotBlank(null) = false
* StringUtils.isNotBlank("")   = false
* StringUtils.isNotBlank(" ")  = false
* StringUtils.isNotBlank("bob")= true
* StringUtils.isNotBlank("  bob  ") = true

7.isAnyBlank()

描述:只要有一个字符为空白符,就返回true。

* StringUtils.isAnyBlank(null)   = true
* StringUtils.isAnyBlank(null, "foo") = true
* StringUtils.isAnyBlank(null, null)  = true
* StringUtils.isAnyBlank("", "bar")   = true
* StringUtils.isAnyBlank("bob", "")   = true
* StringUtils.isAnyBlank("  bob  ", null)  = true
* StringUtils.isAnyBlank(" ", "bar")  = true
* StringUtils.isAnyBlank("foo", "bar")= false

8.isNoneBlank()

描述:对isAnyBlank取反。

* StringUtils.isNoneBlank(null)   = false
* StringUtils.isNoneBlank(null, "foo") = false
* StringUtils.isNoneBlank(null, null)  = false
* StringUtils.isNoneBlank("", "bar")   = false
* StringUtils.isNoneBlank("bob", "")   = false
* StringUtils.isNoneBlank("  bob  ", null)  = false
* StringUtils.isNoneBlank(" ", "bar")  = false
* StringUtils.isNoneBlank("foo", "bar")= true

9.trim()

描述:trim功能是修剪字符串两边的空格,修剪后的空串会保持空串。

* StringUtils.trim(null)= null
* StringUtils.trim("")  = ""
* StringUtils.trim("")  = ""
* StringUtils.trim("abc")    = "abc"
* StringUtils.trim("    abc    ") = "abc"

10.trimToNull()

描述:trimToNull在trim的基础上,将修剪后的空串转化为null。

* StringUtils.trimToNull(null)= null
* StringUtils.trimToNull("")  = null
* StringUtils.trimToNull("")  = null
* StringUtils.trimToNull("abc")    = "abc"
* StringUtils.trimToNull("    abc    ") = "abc"

11.trimToEmpty()

描述:trimToEmpty在trim的基础上,将修剪后的null转化为空串。

* StringUtils.trimToEmpty(null)= ""
* StringUtils.trimToEmpty("")  = ""
* StringUtils.trimToEmpty("")  = ""
* StringUtils.trimToEmpty("abc")    = "abc"
* StringUtils.trimToEmpty("    abc    ") = "abc"

12.strip()

描述:strip功能与trim对应,有两个参数的strip重载则可以指定要在字符串开头与结尾需要删除的字符串。

* StringUtils.strip(null)= null
* StringUtils.strip("")  = ""
* StringUtils.strip("   ")    = ""
* StringUtils.strip("abc")    = "abc"
* StringUtils.strip("  abc")  = "abc"
* StringUtils.strip("abc  ")  = "abc"
* StringUtils.strip(" abc ")  = "abc"
* StringUtils.strip(" ab c ") = "ab c"
* StringUtils.strip(null, *)= null
* StringUtils.strip("", *)  = ""
* StringUtils.strip("abc", null) = "abc"
* StringUtils.strip("  abc", null)    = "abc"
* StringUtils.strip("abc  ", null)    = "abc"
* StringUtils.strip(" abc ", null)    = "abc"
* StringUtils.strip("  abcyx", "xyz") = "  abc"

13.stripToNull()

描述:stripToNull功能与trimToNull对应,有两个参数的strip重载则可以指定要在字符串开头与结尾需要删除的字符串。

* StringUtils.stripToNull(null)= null
* StringUtils.stripToNull("")  = null
* StringUtils.stripToNull("   ")    = null
* StringUtils.stripToNull("abc")    = "abc"
* StringUtils.stripToNull("  abc")  = "abc"
* StringUtils.stripToNull("abc  ")  = "abc"
* StringUtils.stripToNull(" abc ")  = "abc"
* StringUtils.stripToNull(" ab c ") = "ab c"

14.stripToEmpty()

描述:stripToEmpty功能与trimToEmpty对应,有两个参数的strip重载则可以指定要在字符串开头与结尾需要删除的字符串。

* StringUtils.stripToEmpty(null)= ""
* StringUtils.stripToEmpty("")  = ""
* StringUtils.stripToEmpty("   ")    = ""
* StringUtils.stripToEmpty("abc")    = "abc"
* StringUtils.stripToEmpty("  abc")  = "abc"
* StringUtils.stripToEmpty("abc  ")  = "abc"
* StringUtils.stripToEmpty(" abc ")  = "abc"
* StringUtils.stripToEmpty(" ab c ") = "ab c"

15.stripStart()

描述:stripStart是实现在字符串开头删除指定的字符串。也就是strip系列方法的主要实现依赖之一。

* StringUtils.stripStart(null, *)= null
* StringUtils.stripStart("", *)  = ""
* StringUtils.stripStart("abc", "")   = "abc"
* StringUtils.stripStart("abc", null) = "abc"
* StringUtils.stripStart("  abc", null)    = "abc"
* StringUtils.stripStart("abc  ", null)    = "abc  "
* StringUtils.stripStart(" abc ", null)    = "abc "
* StringUtils.stripStart("yxabc  ", "xyz") = "abc  "

16.stripEnd()

描述:stripEnd是实现在字符串结尾删除指定的字符串。也就是strip系列方法的主要实现依赖之一。

* StringUtils.stripEnd(null, *)= null
* StringUtils.stripEnd("", *)  = ""
* StringUtils.stripEnd("abc", "")   = "abc"
* StringUtils.stripEnd("abc", null) = "abc"
* StringUtils.stripEnd("  abc", null)    = "  abc"
* StringUtils.stripEnd("abc  ", null)    = "abc"
* StringUtils.stripEnd(" abc ", null)    = " abc"
* StringUtils.stripEnd("  abcyx", "xyz") = "  abc"
* StringUtils.stripEnd("120.00", ".0")   = "12"

17.stripAll()

描述:stripAll有默认删除字符串数组的前后空格功能与删除指定的前后字符串的重载方法。

* StringUtils.stripAll(null)   = null
* StringUtils.stripAll([])= []
* StringUtils.stripAll(["abc", "  abc"]) = ["abc", "abc"]
* StringUtils.stripAll(["abc  ", null])  = ["abc", null]
* StringUtils.stripAll(null, *) = null
* StringUtils.stripAll([], *)   = []
* StringUtils.stripAll(["abc", "  abc"], null) = ["abc", "abc"]
* StringUtils.stripAll(["abc  ", null], null)  = ["abc", null]
* StringUtils.stripAll(["abc  ", null], "yz")  = ["abc  ", null]
* StringUtils.stripAll(["yabcz", null], "yz")  = ["abc", null]

18.stripAccents()

描述:stripAccents是删除关于发音的字符,我们基本不会用到。

* StringUtils.stripAccents(null) = null
* StringUtils.stripAccents("")   = ""
* StringUtils.stripAccents("control") = "control"
* StringUtils.stripAccents("éclair")= "eclair"

19.indexOf()

描述:indexOf有四个重载,功能分别为:查找字符序列第一个匹配的字符的位置;根据指定的开始位置,查找字符序列第一个匹配的字符的位置;查找字符序列第一个匹配的字符序列的位置;根据指定的开始位置,查找字符序列第一个匹配的字符序列的位置;

* StringUtils.indexOf(null, *)    = -1
* StringUtils.indexOf("", *) = -1
* StringUtils.indexOf("aabaabaa", 'a') = 0
* StringUtils.indexOf("aabaabaa", 'b') = 2

* StringUtils.indexOf(null, *, *)= -1
* StringUtils.indexOf("", *, *)  = -1
* StringUtils.indexOf("aabaabaa", 'b', 0)  = 2
* StringUtils.indexOf("aabaabaa", 'b', 3)  = 5
* StringUtils.indexOf("aabaabaa", 'b', 9)  = -1
* StringUtils.indexOf("aabaabaa", 'b', -1) = 2

* StringUtils.indexOf(null, *)= -1
* StringUtils.indexOf(*, null)= -1
* StringUtils.indexOf("", "") = 0
* StringUtils.indexOf("", *)  = -1 (except when * = "")
* StringUtils.indexOf("aabaabaa", "a")  = 0
* StringUtils.indexOf("aabaabaa", "b")  = 2
* StringUtils.indexOf("aabaabaa", "ab") = 1
* StringUtils.indexOf("aabaabaa", "")   = 0

* StringUtils.indexOf(null, *, *)= -1
* StringUtils.indexOf(*, null, *)= -1
* StringUtils.indexOf("", "", 0) = 0
* StringUtils.indexOf("", *, 0)  = -1 (except when * = "")
* 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

20.indexOfIgnoreCase()

描述:indexOfIgnoreCase有二个重载,是indexOf两个方法忽略大小写的实现。功能分别为:不区分大小写地查找字符序列第一个匹配的字符序列的位置;根据指定的开始位置,不分大小写地查找字符序列第一个匹配的字符序列的位置;

* StringUtils.indexOfIgnoreCase(null, *)= -1
* StringUtils.indexOfIgnoreCase(*, null)= -1
* StringUtils.indexOfIgnoreCase("", "") = 0
* StringUtils.indexOfIgnoreCase("aabaabaa", "a")  = 0
* StringUtils.indexOfIgnoreCase("aabaabaa", "b")  = 2
* StringUtils.indexOfIgnoreCase("aabaabaa", "ab") = 1

* StringUtils.indexOfIgnoreCase(null, *, *)= -1
* StringUtils.indexOfIgnoreCase(*, null, *)= -1
* StringUtils.indexOfIgnoreCase("", "", 0) = 0
* StringUtils.indexOfIgnoreCase("aabaabaa", "A", 0)  = 0
* StringUtils.indexOfIgnoreCase("aabaabaa", "B", 0)  = 2
* StringUtils.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1
* StringUtils.indexOfIgnoreCase("aabaabaa", "B", 3)  = 5
* StringUtils.indexOfIgnoreCase("aabaabaa", "B", 9)  = -1
* StringUtils.indexOfIgnoreCase("aabaabaa", "B", -1) = 2
* StringUtils.indexOfIgnoreCase("aabaabaa", "", 2)   = 2
* StringUtils.indexOfIgnoreCase("abc", "", 9)   = 3

21.ordinalIndexOf()

描述:在indexOf的基础上添加了一个序数参数,功能分别为:根据指定的开序数,查找字符序列第序数个匹配的字符的位置。

* 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", "", 1)   = 0
* StringUtils.ordinalIndexOf("aabaabaa", "", 2)   = 0

22.lastIndexOf()

描述:lastIndexOf有四个重载,功能分别为:查找字符序列最后一个匹配的字符的位置;根据指定的结束位置,查找字符序列最后一个匹配的字符的位置;查找字符序列最后一个匹配的字符序列的位置;根据指定的结束位置,查找字符序列最后一个匹配的字符序列的位置;

* StringUtils.lastIndexOf(null, *)    = -1
* StringUtils.lastIndexOf("", *) = -1
* StringUtils.lastIndexOf("aabaabaa", 'a') = 7
* StringUtils.lastIndexOf("aabaabaa", 'b') = 5

* StringUtils.lastIndexOf(null, *, *)= -1
* StringUtils.lastIndexOf("", *,  *) = -1
* StringUtils.lastIndexOf("aabaabaa", 'b', 8)  = 5
* StringUtils.lastIndexOf("aabaabaa", 'b', 4)  = 2
* StringUtils.lastIndexOf("aabaabaa", 'b', 0)  = -1
* StringUtils.lastIndexOf("aabaabaa", 'b', 9)  = 5
* StringUtils.lastIndexOf("aabaabaa", 'b', -1) = -1
* StringUtils.lastIndexOf("aabaabaa", 'a', 0)  = 0

* StringUtils.lastIndexOf(null, *)= -1
* StringUtils.lastIndexOf(*, null)= -1
* StringUtils.lastIndexOf("", "") = 0
* StringUtils.lastIndexOf("aabaabaa", "a")  = 7
* StringUtils.lastIndexOf("aabaabaa", "b")  = 5
* StringUtils.lastIndexOf("aabaabaa", "ab") = 4
* StringUtils.lastIndexOf("aabaabaa", "")   = 8

* StringUtils.lastIndexOf(null, *, *)= -1
* StringUtils.lastIndexOf(*, null, *)= -1
* StringUtils.lastIndexOf("aabaabaa", "a", 8)  = 7
* StringUtils.lastIndexOf("aabaabaa", "b", 8)  = 5
* StringUtils.lastIndexOf("aabaabaa", "ab", 8) = 4
* StringUtils.lastIndexOf("aabaabaa", "b", 9)  = 5
* StringUtils.lastIndexOf("aabaabaa", "b", -1) = -1
* StringUtils.lastIndexOf("aabaabaa", "a", 0)  = 0
* StringUtils.lastIndexOf("aabaabaa", "b", 0)  = -1
* StringUtils.lastIndexOf("aabaabaa", "b", 1)  = -1
* StringUtils.lastIndexOf("aabaabaa", "b", 2)  = 2
* StringUtils.lastIndexOf("aabaabaa", "ba", 2)  = -1
* StringUtils.lastIndexOf("aabaabaa", "ba", 2)  = 2

23.lastOrdinalIndexOf()

描述:lastOrdinalIndexOf可以参考OrdinalIndexOf,查找的是倒数ordinal个匹配的字符序列。

 * StringUtils.lastOrdinalIndexOf(null, *, *)= -1
* StringUtils.lastOrdinalIndexOf(*, null, *)= -1
* StringUtils.lastOrdinalIndexOf("", "", *) = 0
* StringUtils.lastOrdinalIndexOf("aabaabaa", "a", 1)  = 7
* StringUtils.lastOrdinalIndexOf("aabaabaa", "a", 2)  = 6
* StringUtils.lastOrdinalIndexOf("aabaabaa", "b", 1)  = 5
* StringUtils.lastOrdinalIndexOf("aabaabaa", "b", 2)  = 2
* StringUtils.lastOrdinalIndexOf("aabaabaa", "ab", 1) = 4
* StringUtils.lastOrdinalIndexOf("aabaabaa", "ab", 2) = 1
* StringUtils.lastOrdinalIndexOf("aabaabaa", "", 1)   = 8
* StringUtils.lastOrdinalIndexOf("aabaabaa", "", 2)   = 8

24.lastIndexOfIgnoreCase()

描述:lastIndexOfIgnoreCase有两个重载方法,可以参考indexOfIgnoreCase。功能分别为,在忽略大小写的情况下,查找最后一个匹配的字符序列的位置;根据所给的结束位置,在忽略大小写的情况下,查找最后一个匹配的字符序列的位置

* StringUtils.lastIndexOfIgnoreCase(null, *)= -1
* StringUtils.lastIndexOfIgnoreCase(*, null)= -1
* StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A")  = 7
* StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B")  = 5
* StringUtils.lastIndexOfIgnoreCase("aabaabaa", "AB") = 4

* StringUtils.lastIndexOfIgnoreCase(null, *, *)= -1
* StringUtils.lastIndexOfIgnoreCase(*, null, *)= -1
* StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A", 8)  = 7
* StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", 8)  = 5
* StringUtils.lastIndexOfIgnoreCase("aabaabaa", "AB", 8) = 4
* StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", 9)  = 5
* StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", -1) = -1
* StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A", 0)  = 0
* StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", 0)  = -1

25.equals()

描述:equals是判断两个字符序列是否相等。

* StringUtils.equals(null, null)   = true
* StringUtils.equals(null, "abc")  = false
* StringUtils.equals("abc", null)  = false
* StringUtils.equals("abc", "abc") = true
* StringUtils.equals("abc", "ABC") = false

26.equalsIgnoreCase()

描述:equalsIgnoreCase是不区分大小写地判断两个字符序列是否相等。

* StringUtils.equalsIgnoreCase(null, null)   = true
* StringUtils.equalsIgnoreCase(null, "abc")  = false
* StringUtils.equalsIgnoreCase("abc", null)  = false
* StringUtils.equalsIgnoreCase("abc", "abc") = true
* StringUtils.equalsIgnoreCase("abc", "ABC") = true

27.contains()

描述:字符序列seq是否包含字符searchChar,包含返回true,不包含返回false

* StringUtils.contains(null, *)= false
* StringUtils.contains(*, null)= false
* StringUtils.contains("", "") = true
* StringUtils.contains("abc", "")   = true
* StringUtils.contains("abc", "a")  = true
* StringUtils.contains("abc", "z")  = false
* StringUtils.contains("", *) = false

28.containsIgnoreCase()

描述:在忽略大小写的前提下,字符序列str是否包含字符序列searchStr,包含返回true,不包含返回false。

* StringUtils.contains(null, *) = false
* StringUtils.contains(*, null) = false
* StringUtils.contains("", "") = true
* StringUtils.contains("abc", "") = true
* StringUtils.contains("abc", "a") = true
* StringUtils.contains("abc", "z") = false
* StringUtils.contains("abc", "A") = true
* StringUtils.contains("abc", "Z") = false

29.containsWhitespace()

描述:判断字符序列是否包含空格,包含返回true,否则返回false

* StringUtils.containsWhitespace("abc") = false;
* StringUtils.containsWhitespace("ab c") = true;

30.indexOfAny()

描述:根据给定的字符数组或字符串,在字符序列中返回第一个匹配的字符数组或字符串的任意字符的位置。

* StringUtils.indexOfAny(null, *) = -1
* StringUtils.indexOfAny("", *)   = -1
* StringUtils.indexOfAny(*, null) = -1
* StringUtils.indexOfAny(*, [])   = -1
* StringUtils.indexOfAny("zzabyycdxx",['z','a']) = 0
* StringUtils.indexOfAny("zzabyycdxx",['b','y']) = 3
* StringUtils.indexOfAny("aba", ['z']) = -1
* 
* StringUtils.indexOfAny(*, "")    = -1
* StringUtils.indexOfAny("zzabyycdxx", "za") = 0
* StringUtils.indexOfAny("zzabyycdxx", "by") = 3
* StringUtils.indexOfAny("aba","z")= -1

31.containsAny()

描述:根据给定的字符数组或字符串,在字符序列中判断是否包含任意一个字符数组或字符串的字符,包含返回true,否则返回false。

* StringUtils.containsAny(null, *) = false
* StringUtils.containsAny("", *)   = false
* StringUtils.containsAny(*, null) = false
* StringUtils.containsAny(*, [])   = false
* StringUtils.containsAny("zzabyycdxx",['z','a']) = true
* StringUtils.containsAny("zzabyycdxx",['b','y']) = true
* StringUtils.containsAny("aba", ['z']) = false

* StringUtils.containsAny(null, *)  = false
* StringUtils.containsAny("", *)    = false
* StringUtils.containsAny(*, null)  = false
* StringUtils.containsAny(*, "")    = false
* StringUtils.containsAny("zzabyycdxx", "za") = true
* StringUtils.containsAny("zzabyycdxx", "by") = true
* StringUtils.containsAny("aba","z")= false

32.indexOfAnyBut()

描述:在字符序列cs中,查找第一个匹配的不在所给字符数组/字符序列searchChars中的字符的位置。

* StringUtils.indexOfAnyBut(null, *)= -1
* StringUtils.indexOfAnyBut("", *)  = -1
* StringUtils.indexOfAnyBut(*, null)= -1
* StringUtils.indexOfAnyBut(*, [])  = -1
* StringUtils.indexOfAnyBut("zzabyycdxx", new char[] {'z', 'a'} ) = 3
* StringUtils.indexOfAnyBut("aba", new char[] {'z'} )   = 0
* StringUtils.indexOfAnyBut("aba", new char[] {'a', 'b'} )   = -1

* StringUtils.indexOfAnyBut(null, *)  = -1
* StringUtils.indexOfAnyBut("", *)    = -1
* StringUtils.indexOfAnyBut(*, null)  = -1
* StringUtils.indexOfAnyBut(*, "")    = -1
* StringUtils.indexOfAnyBut("zzabyycdxx", "za") = 3
* StringUtils.indexOfAnyBut("zzabyycdxx", "")   = -1
* StringUtils.indexOfAnyBut("aba","ab")    = -1

33.containsOnly()

描述:判断字符序列cs是否只包含字符数组或字符串valid给定的字符。只包含则返回true,还有其他字符则返回false。

* StringUtils.containsOnly(null, *)  = false
* StringUtils.containsOnly(*, null)  = false
* StringUtils.containsOnly("", *)    = true
* StringUtils.containsOnly("ab", '') = false
* StringUtils.containsOnly("abab", 'abc') = true
* StringUtils.containsOnly("ab1", 'abc')  = false
* StringUtils.containsOnly("abz", 'abc')  = false

* StringUtils.containsOnly(null, *)  = false
* StringUtils.containsOnly(*, null)  = false
* StringUtils.containsOnly("", *)    = true
* StringUtils.containsOnly("ab", "") = false
* StringUtils.containsOnly("abab", "abc") = true
* StringUtils.containsOnly("ab1", "abc")  = false
* StringUtils.containsOnly("abz", "abc")  = false

34.containsNone()

描述:检查字符序列cs是否不包含字符数组或字符串searchChars的字符。不包含返回true,包含返回false。

* StringUtils.containsNone(null, *)  = true
* StringUtils.containsNone(*, null)  = true
* StringUtils.containsNone("", *)    = true
* StringUtils.containsNone("ab", '') = true
* StringUtils.containsNone("abab", 'xyz') = true
* StringUtils.containsNone("ab1", 'xyz')  = true
* StringUtils.containsNone("abz", 'xyz')  = false

* StringUtils.containsNone(null, *)  = true
* StringUtils.containsNone(*, null)  = true
* StringUtils.containsNone("", *)    = true
* StringUtils.containsNone("ab", "") = true
* StringUtils.containsNone("abab", "xyz") = true
* StringUtils.containsNone("ab1", "xyz")  = true
* StringUtils.containsNone("abz", "xyz")  = false

35.indexOfAny()

描述:根据给定的字符序列数组searchStrs,在字符序列str中查找第一个匹配的任意一个字符序列数组的字符序列的位置。

* StringUtils.indexOfAny(null, *) = -1
* StringUtils.indexOfAny(*, null) = -1
* StringUtils.indexOfAny(*, [])   = -1
* StringUtils.indexOfAny("zzabyycdxx", ["ab","cd"])   = 2
* StringUtils.indexOfAny("zzabyycdxx", ["cd","ab"])   = 2
* StringUtils.indexOfAny("zzabyycdxx", ["mn","op"])   = -1
* StringUtils.indexOfAny("zzabyycdxx", ["zab","aby"]) = 1
* StringUtils.indexOfAny("zzabyycdxx", [""])= 0
* StringUtils.indexOfAny("", [""])= 0
* StringUtils.indexOfAny("", ["a"])    = -1

36.lastIndexOfAny()

描述:根据给定的字符序列数组searchStrs,在字符序列str中查找最后一个匹配的任意一个字符序列数组的字符序列的位置。

* StringUtils.lastIndexOfAny(null, *)    = -1
* StringUtils.lastIndexOfAny(*, null)    = -1
* StringUtils.lastIndexOfAny(*, []) = -1
* StringUtils.lastIndexOfAny(*, [null])  = -1
* StringUtils.lastIndexOfAny("zzabyycdxx", ["ab","cd"]) = 6
* StringUtils.lastIndexOfAny("zzabyycdxx", ["cd","ab"]) = 6
* StringUtils.lastIndexOfAny("zzabyycdxx", ["mn","op"]) = -1
* StringUtils.lastIndexOfAny("zzabyycdxx", ["mn","op"]) = -1
* StringUtils.lastIndexOfAny("zzabyycdxx", ["mn",""])   = 10

37.substring()

描述:根据所给的start和end截取字符串str,半开半闭、有前无后。

* StringUtils.substring(null, *)   = null
* StringUtils.substring("", *)= ""
* StringUtils.substring("abc", 0)  = "abc"
* StringUtils.substring("abc", 2)  = "c"
* StringUtils.substring("abc", 4)  = ""
* StringUtils.substring("abc", -2) = "bc"
* StringUtils.substring("abc", -4) = "abc"

* StringUtils.substring(null, *, *)    = null
* StringUtils.substring("", * ,  *)    = "";
* StringUtils.substring("abc", 0, 2)   = "ab"
* StringUtils.substring("abc", 2, 0)   = ""
* StringUtils.substring("abc", 2, 4)   = "c"
* StringUtils.substring("abc", 4, 6)   = ""
* StringUtils.substring("abc", 2, 2)   = ""
* StringUtils.substring("abc", -2, -1) = "b"
* StringUtils.substring("abc", -4, 2)  = "ab"

38.left()

描述:跟据所给的pos与len分别获取字符串左边str的字符,长度都为len。

* StringUtils.left(null, *)    = null
* StringUtils.left(*, -ve)= ""
* StringUtils.left("", *) = ""
* StringUtils.left("abc", 0)   = ""
* StringUtils.left("abc", 2)   = "ab"
* StringUtils.left("abc", 4)   = "abc"

39.right()

描述:跟据所给的pos与len分别获取字符串str右边的字符,长度都为len。

* StringUtils.right(null, *)    = null
* StringUtils.right(*, -ve)= ""
* StringUtils.right("", *) = ""
* StringUtils.right("abc", 0)   = ""
* StringUtils.right("abc", 2)   = "bc"
* StringUtils.right("abc", 4)   = "abc"

40.mid()

描述:跟据所给的pos与len分别获取字符串str中间的字符,长度都为len

 * StringUtils.mid(null, *, *)    = null
* StringUtils.mid(*, *, -ve)= ""
* StringUtils.mid("", 0, *) = ""
* StringUtils.mid("abc", 0, 2)   = "ab"
* StringUtils.mid("abc", 0, 4)   = "abc"
* StringUtils.mid("abc", 2, 4)   = "c"
* StringUtils.mid("abc", 4, 2)   = ""
* StringUtils.mid("abc", -2, 2)  = "ab"

41.substringBefore()

描述: substringBefore会返回匹配的第一个分隔符separator之前不包含分隔符的字符串。

* StringUtils.substringBefore(null, *) = null
* StringUtils.substringBefore("", *)   = ""
* StringUtils.substringBefore("abc", "a")   = ""
* StringUtils.substringBefore("abcba", "b") = "a"
* StringUtils.substringBefore("abc", "c")   = "ab"
* StringUtils.substringBefore("abc", "d")   = "abc"
* StringUtils.substringBefore("abc", "")    = ""
* StringUtils.substringBefore("abc", null)  = "abc"

42.substringAfter()

描述: substringAfter会返回匹配的第一个分隔符separator之后不包含分隔符的字符串。

* StringUtils.substringAfter(null, *) = null
* StringUtils.substringAfter("", *)   = ""
* StringUtils.substringAfter(*, null) = ""
* StringUtils.substringAfter("abc", "a")   = "bc"
* StringUtils.substringAfter("abcba", "b") = "cba"
* StringUtils.substringAfter("abc", "c")   = ""
* StringUtils.substringAfter("abc", "d")   = ""
* StringUtils.substringAfter("abc", "")    = "abc"

43.substringBeforeLast()

描述:substringBeforeLast会返回匹配的最后一个分隔符separator之前不包含分隔符的字符串。

* StringUtils.substringBeforeLast(null, *) = null
* StringUtils.substringBeforeLast("", *)   = ""
* StringUtils.substringBeforeLast("abcba", "b") = "abc"
* StringUtils.substringBeforeLast("abc", "c")   = "ab"
* StringUtils.substringBeforeLast("a", "a")= ""
* StringUtils.substringBeforeLast("a", "z")= "a"
* StringUtils.substringBeforeLast("a", null)    = "a"
* StringUtils.substringBeforeLast("a", "") = "a"

44.substringAfterLast()

描述:substringAfterLast会返回匹配的最后一个分隔符separator之后不包含分隔符的字符串。

* StringUtils.substringAfterLast(null, *) = null
* StringUtils.substringAfterLast("", *)   = ""
* StringUtils.substringAfterLast(*, "")   = ""
* StringUtils.substringAfterLast(*, null) = ""
* StringUtils.substringAfterLast("abc", "a")   = "bc"
* StringUtils.substringAfterLast("abcba", "b") = "a"
* StringUtils.substringAfterLast("abc", "c")   = ""
* StringUtils.substringAfterLast("a", "a")= ""
* StringUtils.substringAfterLast("a", "z")= ""

45.substringBetween()

描述:substringBetween的两个重载功能分别为:根据传入的tag来截取两个tag间的子字符串,仅返回首次匹配到的子字符串。根据传入的字符串open与字符串close来截取子字符串,仅返回首次匹配到的子字符串。

* StringUtils.substringBetween(null, *)  = null
* StringUtils.substringBetween("", "")   = ""
* StringUtils.substringBetween("", "tag")= null
* StringUtils.substringBetween("tagabctag", null)  = null
* StringUtils.substringBetween("tagabctag", "")    = ""
* StringUtils.substringBetween("tagabctag", "tag") = "abc"

* StringUtils.substringBetween("wx[b]yz", "[", "]") = "b"
* StringUtils.substringBetween(null, *, *)= null
* StringUtils.substringBetween(*, null, *)= null
* StringUtils.substringBetween(*, *, null)= null
* StringUtils.substringBetween("", "", "")= ""
* StringUtils.substringBetween("", "", "]")    = null
* StringUtils.substringBetween("", "[", "]")   = null
* StringUtils.substringBetween("yabcz", "", "")= ""
* StringUtils.substringBetween("yabcz", "y", "z")   = "abc"
* StringUtils.substringBetween("yabczyabcz", "y", "z")   = "abc"

46.substringsBetween()

描述:substringsBetween的功能为:根据传入的字符串open与字符串close来截取子字符串,返回
所有匹配到的子字符串,所以返回的对象时字符串数组。

* StringUtils.substringsBetween("[a][b][c]", "[", "]") = ["a","b","c"]
* StringUtils.substringsBetween(null, *, *)  = null
* StringUtils.substringsBetween(*, null, *)  = null
* StringUtils.substringsBetween(*, *, null)  = null
* StringUtils.substringsBetween("", "[", "]")= []

47.split()

描述:split的重载功能分别为:将字符空格作为分隔符,返回字符串str分隔后的字符串数组。将传入的字符separatorChar作为分隔符,返回字符串str分隔后的字符串数组。将传入的字符串separatorChars作为分隔符,返回字符串str分隔后的字符串数组。将传入的字符串separatorChars作为分隔符,返回字符串str分隔后长度不大于max的字符串数组,多余的部分不分割,并入最后一个元素。

* StringUtils.split(null)  = null
* StringUtils.split("")    = []
* StringUtils.split("abc def")  = ["abc", "def"]
* StringUtils.split("abc  def") = ["abc", "def"]
* StringUtils.split(" abc ")    = ["abc"]

* StringUtils.split(null, *)    = null
* StringUtils.split("", *) = []
* StringUtils.split("a.b.c", '.')    = ["a", "b", "c"]
* StringUtils.split("a..b.c", '.')   = ["a", "b", "c"]
* StringUtils.split("a:b:c", '.')    = ["a:b:c"]
* StringUtils.split("a b c", ' ')    = ["a", "b", "c"]

* StringUtils.split(null, *)    = null
* StringUtils.split("", *) = []
* StringUtils.split("abc def", null) = ["abc", "def"]
* StringUtils.split("abc def", " ")  = ["abc", "def"]
* StringUtils.split("abc  def", " ") = ["abc", "def"]
* StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"]

* StringUtils.split(null, *, *)  = null
* StringUtils.split("", *, *)    = []
* StringUtils.split("ab cd ef", null, 0)   = ["ab", "cd", "ef"]
* StringUtils.split("ab   cd ef", null, 0) = ["ab", "cd", "ef"]
* StringUtils.split("ab:cd:ef", ":", 0)    = ["ab", "cd", "ef"]
* StringUtils.split("ab:cd:ef", ":", 2)    = ["ab", "cd:ef"]

48.splitByWholeSeparator()和splitByWholeSeparatorPreserveAllTokens()

描述:splitByWholeSeparator的重载功能分别为:将传入的字符串separator作为分隔符,返回字符串str分隔后的字符串数组。

* StringUtils.splitByWholeSeparator(null, *)= null
* StringUtils.splitByWholeSeparator("", *)  = []
* StringUtils.splitByWholeSeparator("ab de fg", null) = ["ab", "de", "fg"]
* StringUtils.splitByWholeSeparator("ab   de fg", null)    = ["ab", "de", "fg"]
* StringUtils.splitByWholeSeparator("ab:cd:ef", ":")  = ["ab", "cd", "ef"]
* StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-") = ["ab", "cd", "ef"]

* StringUtils.splitByWholeSeparator(null, *, *)= null
* StringUtils.splitByWholeSeparator("", *, *)  = []
* StringUtils.splitByWholeSeparator("ab de fg", null, 0) = ["ab", "de", "fg"]
* StringUtils.splitByWholeSeparator("ab   de fg", null, 0)    = ["ab", "de", "fg"]
* StringUtils.splitByWholeSeparator("ab:cd:ef", ":", 2)  = ["ab", "cd:ef"]
* StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-", 5) = ["ab", "cd", "ef"]
* StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-", 2) = ["ab", "cd-!-ef"]
* StringUtils.splitByWholeSeparatorPreserveAllTokens(null, *)= null
* StringUtils.splitByWholeSeparatorPreserveAllTokens("", *)  = []
* StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null) = ["ab", "de", "fg"]
* StringUtils.splitByWholeSeparatorPreserveAllTokens("ab   de fg", null)    = ["ab", "", "", "de", "fg"]
* StringUtils.splitByWholeSeparatorPreserveAllTokens("ab:cd:ef", ":")  = ["ab", "cd", "ef"]
* StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-") = ["ab", "cd", "ef"]

* StringUtils.splitByWholeSeparatorPreserveAllTokens(null, *, *)= null
* StringUtils.splitByWholeSeparatorPreserveAllTokens("", *, *)  = []
* StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null, 0) = ["ab", "de", "fg"]
* StringUtils.splitByWholeSeparatorPreserveAllTokens("ab   de fg", null, 0)    = ["ab", "", "", "de", "fg"]
* StringUtils.splitByWholeSeparatorPreserveAllTokens("ab:cd:ef", ":", 2)  = ["ab", "cd:ef"]
* StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-", 5) = ["ab", "cd", "ef"]
* StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-", 2) = ["ab", "cd-!-ef"]

49.splitPreserveAllTokens()

描述:splitPreserveAllTokens的四个重载功能分别为:
根据空格作为分隔符,将字符串str分隔为字符串数组,重复的分隔符是空串的分隔。
将传入的separatorChar作为分隔符,将字符串str分隔为字符串数组,重复的分隔符是空串的分隔。
将传入的separatorChars作为分隔符,将字符串str分隔为字符串数组,重复的分隔符是空串的分隔。
将传入的separatorChars作为分隔符,将字符串str分隔为字符串数组,数组大小不大于max,余下的并入最后一个数组元素,重复的分隔符是空串的分隔。

* StringUtils.splitPreserveAllTokens(null)  = null
* StringUtils.splitPreserveAllTokens("")    = []
* StringUtils.splitPreserveAllTokens("abc def")  = ["abc", "def"]
* StringUtils.splitPreserveAllTokens("abc  def") = ["abc", "", "def"]
* StringUtils.splitPreserveAllTokens(" abc ")    = ["", "abc", ""]

* StringUtils.splitPreserveAllTokens(null, *)    = null
* StringUtils.splitPreserveAllTokens("", *) = []
* StringUtils.splitPreserveAllTokens("a.b.c", '.')    = ["a", "b", "c"]
* StringUtils.splitPreserveAllTokens("a..b.c", '.')   = ["a", "", "b", "c"]
* StringUtils.splitPreserveAllTokens("a:b:c", '.')    = ["a:b:c"]
* StringUtils.splitPreserveAllTokens("a\tb\nc", null) = ["a", "b", "c"]
* StringUtils.splitPreserveAllTokens("a b c", ' ')    = ["a", "b", "c"]
* StringUtils.splitPreserveAllTokens("a b c ", ' ')   = ["a", "b", "c", ""]
* StringUtils.splitPreserveAllTokens("a b c  ", ' ')   = ["a", "b", "c", "", ""]
* StringUtils.splitPreserveAllTokens(" a b c", ' ')   = ["", a", "b", "c"]
* StringUtils.splitPreserveAllTokens("  a b c", ' ')  = ["", "", a", "b", "c"]
* StringUtils.splitPreserveAllTokens(" a b c ", ' ')  = ["", a", "b", "c", ""]

* StringUtils.splitPreserveAllTokens(null, *) = null
* StringUtils.splitPreserveAllTokens("", *)   = []
* StringUtils.splitPreserveAllTokens("abc def", null)   = ["abc", "def"]
* StringUtils.splitPreserveAllTokens("abc def", " ")    = ["abc", "def"]
* StringUtils.splitPreserveAllTokens("abc  def", " ")   = ["abc", "", def"]
* StringUtils.splitPreserveAllTokens("ab:cd:ef", ":")   = ["ab", "cd", "ef"]
* StringUtils.splitPreserveAllTokens("ab:cd:ef:", ":")  = ["ab", "cd", "ef", ""]
* StringUtils.splitPreserveAllTokens("ab:cd:ef::", ":") = ["ab", "cd", "ef", "", ""]
* StringUtils.splitPreserveAllTokens("ab::cd:ef", ":")  = ["ab", "", cd", "ef"]
* StringUtils.splitPreserveAllTokens(":cd:ef", ":")= ["", cd", "ef"]
* StringUtils.splitPreserveAllTokens("::cd:ef", ":")    = ["", "", cd", "ef"]
* StringUtils.splitPreserveAllTokens(":cd:ef:", ":")    = ["", cd", "ef", ""]

* StringUtils.splitPreserveAllTokens(null, *, *)  = null
* StringUtils.splitPreserveAllTokens("", *, *)    = []
* StringUtils.splitPreserveAllTokens("ab de fg", null, 0)   = ["ab", "cd", "ef"]
* StringUtils.splitPreserveAllTokens("ab   de fg", null, 0) = ["ab", "cd", "ef"]
* StringUtils.splitPreserveAllTokens("ab:cd:ef", ":", 0)    = ["ab", "cd", "ef"]
* StringUtils.splitPreserveAllTokens("ab:cd:ef", ":", 2)    = ["ab", "cd:ef"]
* StringUtils.splitPreserveAllTokens("ab   de fg", null, 2) = ["ab", "  de fg"]
* StringUtils.splitPreserveAllTokens("ab   de fg", null, 3) = ["ab", "", " de fg"]
* StringUtils.splitPreserveAllTokens("ab   de fg", null, 4) = ["ab", "", "", "de fg"]

50.splitByCharacterType()

描述:按照字符串类型来划分字符串str,并返回字符串数组。大小写、数字、特殊字符。

* StringUtils.splitByCharacterType(null)    = null
* StringUtils.splitByCharacterType("") = []
* StringUtils.splitByCharacterType("ab de fg")   = ["ab", " ", "de", " ", "fg"]
* StringUtils.splitByCharacterType("ab   de fg") = ["ab", "   ", "de", " ", "fg"]
* StringUtils.splitByCharacterType("ab:cd:ef")   = ["ab", ":", "cd", ":", "ef"]
* StringUtils.splitByCharacterType("number5")    = ["number", "5"]
* StringUtils.splitByCharacterType("fooBar")= ["foo", "B", "ar"]
* StringUtils.splitByCharacterType("foo200Bar")  = ["foo", "200", "B", "ar"]
* StringUtils.splitByCharacterType("ASFRules")   = ["ASFR", "ules"]

51.splitByCharacterTypeCamelCase()

描述:在splitByCharacterType的基础上,加入驼峰命名的规则来分隔字符串。(仅对大小写有影响)

* StringUtils.splitByCharacterTypeCamelCase(null)    = null
* StringUtils.splitByCharacterTypeCamelCase("") = []
* StringUtils.splitByCharacterTypeCamelCase("ab de fg")   = ["ab", " ", "de", " ", "fg"]
* StringUtils.splitByCharacterTypeCamelCase("ab   de fg") = ["ab", "   ", "de", " ", "fg"]
* StringUtils.splitByCharacterTypeCamelCase("ab:cd:ef")   = ["ab", ":", "cd", ":", "ef"]
* StringUtils.splitByCharacterTypeCamelCase("number5")    = ["number", "5"]
* StringUtils.splitByCharacterTypeCamelCase("fooBar")= ["foo", "Bar"]
* StringUtils.splitByCharacterTypeCamelCase("foo200Bar")  = ["foo", "200", "Bar"]
* StringUtils.splitByCharacterTypeCamelCase("ASFRules")   = ["ASF", "Rules"]

52.join()

描述1:将数组元素合并为一个字符串,元素之间没有分隔符。

* StringUtils.join(null)  = null
* StringUtils.join([])    = ""
* StringUtils.join([null])= ""
* StringUtils.join(["a", "b", "c"]) = "abc"
* StringUtils.join([null, "", "a"]) = "a"

描述2:根据传入参数类型的不同,将传入的数组合并为一个字符串,各元素间的分隔符按照传入的separator设定。

* StringUtils.join(null, *)= null
* StringUtils.join([], *)  = ""
* StringUtils.join([null], *)   = ""
* StringUtils.join(["a", "b", "c"], ';')  = "a;b;c"
* StringUtils.join(["a", "b", "c"], null) = "abc"
* StringUtils.join([null, "", "a"], ';')  = ";;a"

* StringUtils.join(null, *)= null
* StringUtils.join([], *)  = ""
* StringUtils.join([null], *)   = ""
* StringUtils.join([1, 2, 3], ';')  = "1;2;3"
* StringUtils.join([1, 2, 3], null) = "123"

描述3:根据传入参数类型的不同,将传入的数组按照传入的元素起始位置startIndex和结束位置endIndex合并为一个字符串,各元素间的分隔符按照传入的separator设定。

* StringUtils.join(null, *,2,4)= null
* StringUtils.join([], *,4,5)  = ""
* StringUtils.join([null], *,1,5)   = ""
* StringUtils.join(["a", "b", "c","d", "e"], ';',1,4)  = "b;c;d"
* StringUtils.join(["a", "b", "c","d", "e"], null,1,4) = "bcd"
* StringUtils.join([null, "", "a", "",null], ';',1,4)  = ";a;"

* StringUtils.join(null, *,2,4)= null
* StringUtils.join([], *,2,4)  = ""
* StringUtils.join([null], *,1,3)   = ""
* StringUtils.join([1, 2, 3, 4, 5], ';',1,5)  = "2;3;4;5"
* StringUtils.join([1, 2, 3, 4, 5], null,1,5) = "2345"

描述4:根据传入的分隔字符串separator,将数组合并为字符串,各数组元素间用separator隔开。

* StringUtils.join(null, *) = null
* StringUtils.join([], *)   = ""
* StringUtils.join([null], *)    = ""
* StringUtils.join(["a", "b", "c"], "--")  = "a--b--c"
* StringUtils.join(["a", "b", "c"], null)  = "abc"
* StringUtils.join(["a", "b", "c"], "")    = "abc"
* StringUtils.join([null, "", "a"], ',')   = ",,a"

描述5:根据传入的分隔字符串separator,将数组开始位置startIndex与结位置endIndex间的元素,合并为字符串,各数组元素间用separator隔开。

* StringUtils.join(null, *, *, *) = null
* StringUtils.join([], *, *, *)   = ""
* StringUtils.join([null], *, *, *)    = ""
* StringUtils.join(["a", "b", "c"], "--", 0, 3)  = "a--b--c"
* StringUtils.join(["a", "b", "c"], "--", 1, 3)  = "b--c"
* StringUtils.join(["a", "b", "c"], "--", 2, 3)  = "c"
* StringUtils.join(["a", "b", "c"], "--", 2, 2)  = ""
* StringUtils.join(["a", "b", "c"], null, 0, 3)  = "abc"
* StringUtils.join(["a", "b", "c"], "", 0, 3)    = "abc"
* StringUtils.join([null, "", "a"], ',', 0, 3)   = ",,a"

53.deleteWhitespace()

描述:删除字符串中的所有空白符,返回新字符串。

* StringUtils.deleteWhitespace(null)    = null
* StringUtils.deleteWhitespace("") = ""
* StringUtils.deleteWhitespace("abc")   = "abc"
* StringUtils.deleteWhitespace("   ab  c  ") = "abc"

54.removeStart()

描述:仅当字符串remove位于str开头时才删除remove,返回删除后的str,否则返回原串。

* StringUtils.removeStart(null, *) = null
* StringUtils.removeStart("", *)   = ""
* StringUtils.removeStart(*, null) = *
* StringUtils.removeStart("www.domain.com", "www.")   = "domain.com"
* StringUtils.removeStart("domain.com", "www.")  = "domain.com"
* StringUtils.removeStart("www.domain.com", "domain") = "www.domain.com"
* StringUtils.removeStart("abc", "")    = "abc"

55.removeStartIgnoreCase()

描述:在区分大小写 的情况下,仅当字符串remove位于str开头时才删除remove,返回删除后的str,否则返回原串。

* StringUtils.removeStartIgnoreCase(null, *) = null
* StringUtils.removeStartIgnoreCase("", *)   = ""
* StringUtils.removeStartIgnoreCase(*, null) = *
* StringUtils.removeStartIgnoreCase("www.domain.com", "www.")   = "domain.com"
* StringUtils.removeStartIgnoreCase("www.domain.com", "WWW.")   = "domain.com"
* StringUtils.removeStartIgnoreCase("domain.com", "www.")  = "domain.com"
* StringUtils.removeStartIgnoreCase("www.domain.com", "domain") = "www.domain.com"
* StringUtils.removeStartIgnoreCase("abc", "")    = "ab

56.removeEnd()

描述:仅当字符串remove位于str结尾时才删除remove,返回删除后的str,否则返回原串。

* StringUtils.removeEnd(null, *) = null
* StringUtils.removeEnd("", *)   = ""
* StringUtils.removeEnd(*, null) = *
* StringUtils.removeEnd("www.domain.com", ".com.")  = "www.domain.com"
* StringUtils.removeEnd("www.domain.com", ".com")   = "www.domain"
* StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com"
* StringUtils.removeEnd("abc", "")    = "abc"

57.removeEndIgnoreCase()

描述:在区分大小写 的情况下,仅当字符串remove位于str结尾时才删除remove,返回删除后的str,否则返回原串。

* StringUtils.removeEndIgnoreCase(null, *) = null
* StringUtils.removeEndIgnoreCase("", *)   = ""
* StringUtils.removeEndIgnoreCase(*, null) = *
* StringUtils.removeEndIgnoreCase("www.domain.com", ".com.")  = "www.domain.com"
* StringUtils.removeEndIgnoreCase("www.domain.com", ".com")   = "www.domain"
* StringUtils.removeEndIgnoreCase("www.domain.com", "domain") = "www.domain.com"
* StringUtils.removeEndIgnoreCase("abc", "")    = "abc"
* StringUtils.removeEndIgnoreCase("www.domain.com", ".COM") = "www.domain")
* StringUtils.removeEndIgnoreCase("www.domain.COM", ".com") = "www.domain")

58.remove

描述1:删除字符串str中所有的remove子串,返回新串。

* StringUtils.remove(null, *)   = null
* StringUtils.remove("", *)= ""
* StringUtils.remove(*, null)   = *
* StringUtils.remove(*, "")= *
* StringUtils.remove("queued", "ue") = "qd"
* StringUtils.remove("queued", "zz") = "queued"

描述2:删除字符串str中所有的remove字符,返回新串。

* StringUtils.remove(null, *)  = null
* StringUtils.remove("", *)    = ""
* StringUtils.remove("queued", 'u') = "qeed"
* StringUtils.remove("queued", 'z') = "queued"

59.replaceOnce()

描述:将字符串text中第一个匹配的searchString替换为replacement。

* StringUtils.replaceOnce(null, *, *)   = null
* StringUtils.replaceOnce("", *, *)= ""
* StringUtils.replaceOnce("any", null, *)    = "any"
* StringUtils.replaceOnce("any", *, null)    = "any"
* StringUtils.replaceOnce("any", "", *) = "any"
* StringUtils.replaceOnce("aba", "a", null)  = "aba"
* StringUtils.replaceOnce("aba", "a", "")    = "ba"
* StringUtils.replaceOnce("aba", "a", "z")   = "zba"

60.replacePattern()

描述:在字符串source中,将每个匹配正则表达式regex的子字符串替换为字符串replacement。

61.removePattern()

描述:依赖replacePattern实现,将source中每个匹配的regex子串替换为空串,效果相当于删除,返回新串。

62.replace()

描述1:在字符串text中,替换所有searchString字符串为replacement字符串。

* StringUtils.replace(null, *, *)   = null
* StringUtils.replace("", *, *)= ""
* StringUtils.replace("any", null, *)    = "any"
* StringUtils.replace("any", *, null)    = "any"
* StringUtils.replace("any", "", *) = "any"
* StringUtils.replace("aba", "a", null)  = "aba"
* StringUtils.replace("aba", "a", "")    = "b"
* StringUtils.replace("aba", "a", "z")   = "zbz"

描述2:在字符串text中,替换searchString字符串为replacement字符串,最多替换max个。

* StringUtils.replace(null, *, *, *)    = null
* StringUtils.replace("", *, *, *) = ""
* StringUtils.replace("any", null, *, *)= "any"
* StringUtils.replace("any", *, null, *)= "any"
* StringUtils.replace("any", "", *, *)  = "any"
* StringUtils.replace("any", *, *, 0)   = "any"
* StringUtils.replace("abaa", "a", null, -1) = "abaa"
* StringUtils.replace("abaa", "a", "", -1)   = "b"
* StringUtils.replace("abaa", "a", "z", 0)   = "abaa"
* StringUtils.replace("abaa", "a", "z", 1)   = "zbaa"
* StringUtils.replace("abaa", "a", "z", 2)   = "zbza"
* StringUtils.replace("abaa", "a", "z", -1)  = "zbzz"

63.replaceEach()

描述:在字符串text中,将所有的searchList字符串数组元素与replacement字符串数组元素一次性一一对应替换。(即所有元素同时替换)

*  StringUtils.replaceEach(null, *, *)   = null
*  StringUtils.replaceEach("", *, *)= ""
*  StringUtils.replaceEach("aba", null, null) = "aba"
*  StringUtils.replaceEach("aba", new String[0], null) = "aba"
*  StringUtils.replaceEach("aba", null, new String[0]) = "aba"
*  StringUtils.replaceEach("aba", new String[]{"a"}, null)  = "aba"
*  StringUtils.replaceEach("aba", new String[]{"a"}, new String[]{""})  = "b"
*  StringUtils.replaceEach("aba", new String[]{null}, new String[]{"a"})  = "aba"
*  StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"w", "t"})  = "wcte"
*  (example of how it does not repeat)
*  StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"})  = "dcte"

64.replaceEachRepeatedly()

描述:在字符串text中,将所有的searchList字符串数组元素与replacement字符串数组元素串行一一对应替换。(即按每个元素替换后的结果作为下个元素替换的原串)

*  StringUtils.replaceEach(null, *, *, *) = null
*  StringUtils.replaceEach("", *, *, *) = ""
*  StringUtils.replaceEach("aba", null, null, *) = "aba"
*  StringUtils.replaceEach("aba", new String[0], null, *) = "aba"
*  StringUtils.replaceEach("aba", null, new String[0], *) = "aba"
*  StringUtils.replaceEach("aba", new String[]{"a"}, null, *) = "aba"
*  StringUtils.replaceEach("aba", new String[]{"a"}, new String[]{""}, *) = "b"
*  StringUtils.replaceEach("aba", new String[]{null}, new String[]{"a"}, *) = "aba"
*  StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"w", "t"}, *) = "wcte"
*  (example of how it repeats)
*  StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}, false) = "dcte"
*  StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}, true) = "tcte"
*  StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "ab"}, true) = IllegalStateException
*  StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "ab"}, false) = "dcabe"

65.replaceChars()

描述1:在str中匹配字符searchChar,并以字符replaceChar替代。

* StringUtils.replaceChars(null, *, *)   = null
* StringUtils.replaceChars("", *, *)= ""
* StringUtils.replaceChars("abcba", 'b', 'y') = "aycya"
* StringUtils.replaceChars("abcba", 'z', 'y') = "abcba"

描述2:一次替换字符串中的多个字符。此方法也可用于删除字符。拿searchChars的index,去replaceChars找相应的index然后替换掉。

* StringUtils.replaceChars(null, *, *) = null
* StringUtils.replaceChars("", *, *)   = ""
* StringUtils.replaceChars("abc", null, *)  = "abc"
* StringUtils.replaceChars("abc", "", *)    = "abc"
* StringUtils.replaceChars("abc", "b", null)= "ac"
* StringUtils.replaceChars("abc", "b", "")  = "ac"
* StringUtils.replaceChars("abcba", "bc", "yz")  = "ayzya"
* StringUtils.replaceChars("abcba", "bc", "y")   = "ayya"
* StringUtils.replaceChars("abcba", "bc", "yzx") = "ayzya"

66.overlay()

描述:根据start和end将str字符串中相应位置的字符串(可以是空串),替换为overlay

* StringUtils.overlay(null, *, *, *)  = null
* StringUtils.overlay("", "abc", 0, 0)= "abc"
* StringUtils.overlay("abcdef", null, 2, 4)= "abef"
* StringUtils.overlay("abcdef", "", 2, 4)  = "abef"
* StringUtils.overlay("abcdef", "", 4, 2)  = "abef"
* StringUtils.overlay("abcdef", "zzzz", 2, 4)   = "abzzzzef"
* StringUtils.overlay("abcdef", "zzzz", 4, 2)   = "abzzzzef"
* StringUtils.overlay("abcdef", "zzzz", -1, 4)  = "zzzzef"
* StringUtils.overlay("abcdef", "zzzz", 2, 8)   = "abzzzz"
* StringUtils.overlay("abcdef", "zzzz", -2, -3) = "zzzzabcdef"
* StringUtils.overlay("abcdef", "zzzz", 8, 10)  = "abcdefzzzz"

67.chomp()

描述:将字符串str结尾的’\r’ ‘\n’ ‘\r\n’ 中的一种删除(优先删除’\r\n’)。

* StringUtils.chomp(null)= null
* StringUtils.chomp("")  = ""
* StringUtils.chomp("abc \r") = "abc "
* StringUtils.chomp("abc\n")  = "abc"
* StringUtils.chomp("abc\r\n")= "abc"
* StringUtils.chomp("abc\r\n\r\n") = "abc\r\n"
* StringUtils.chomp("abc\n\r")= "abc\n"
* StringUtils.chomp("abc\n\rabc")  = "abc\n\rabc"
* StringUtils.chomp("\r")= ""
* StringUtils.chomp("\n")= ""
* StringUtils.chomp("\r\n")   = ""

68.chop()

描述:删除字符串str的最后一个字符,’\r\n’算一个字符。

* StringUtils.chop(null)= null
* StringUtils.chop("")  = ""
* StringUtils.chop("abc \r") = "abc "
* StringUtils.chop("abc\n")  = "abc"
* StringUtils.chop("abc\r\n")= "abc"
* StringUtils.chop("abc")    = "ab"
* StringUtils.chop("abc\nabc")    = "abc\nab"
* StringUtils.chop("a") = ""
* StringUtils.chop("\r")= ""
* StringUtils.chop("\n")= ""
* StringUtils.chop("\r\n")   = ""

69.repeat()

描述1:重复字符串str,次数为repeat次。

* StringUtils.repeat(null, 2) = null
* StringUtils.repeat("", 0)   = ""
* StringUtils.repeat("", 2)   = ""
* StringUtils.repeat("a", 3)  = "aaa"
* StringUtils.repeat("ab", 2) = "abab"
* StringUtils.repeat("a", -2) = ""

描述2:重复字符串str,次数为repeat次,分隔符为separator。

* StringUtils.repeat(null, null, 2) = null
* StringUtils.repeat(null, "x", 2)  = null
* StringUtils.repeat("", null, 0)   = ""
* StringUtils.repeat("", "", 2)= ""
* StringUtils.repeat("", "x", 3)    = "xxx"
* StringUtils.repeat("?", ", ", 3)  = "?, ?, ?"

描述3:重复字符ch,次数为repeat次。

* StringUtils.repeat('e', 0)  = ""
* StringUtils.repeat('e', 3)  = "eee"
* StringUtils.repeat('e', -2) = ""

70.rightPad()

描述1:若str长度不足size,则使用空格在字符串后补全。

* StringUtils.rightPad(null, *)   = null
* StringUtils.rightPad("", 3)= "   "
* StringUtils.rightPad("bat", 3)  = "bat"
* StringUtils.rightPad("bat", 5)  = "bat  "
* StringUtils.rightPad("bat", 1)  = "bat"
* StringUtils.rightPad("bat", -1) = "bat"

描述2:若str长度不足size,则使用padChar字符在字符串后补全。

* StringUtils.rightPad(null, *, *)= null
* StringUtils.rightPad("", 3, 'z')= "zzz"
* StringUtils.rightPad("bat", 3, 'z')  = "bat"
* StringUtils.rightPad("bat", 5, 'z')  = "batzz"
* StringUtils.rightPad("bat", 1, 'z')  = "bat"
* StringUtils.rightPad("bat", -1, 'z') = "bat"

描述3:若str长度不足size,则使用padStr字符串在字符串后补全,padStr可以截断。

* StringUtils.rightPad(null, *, *) = null
* StringUtils.rightPad("", 3, "z") = "zzz"
* StringUtils.rightPad("bat", 3, "yz")  = "bat"
* StringUtils.rightPad("bat", 5, "yz")  = "batyz"
* StringUtils.rightPad("bat", 8, "yz")  = "batyzyzy"
* StringUtils.rightPad("bat", 1, "yz")  = "bat"
* StringUtils.rightPad("bat", -1, "yz") = "bat"
* StringUtils.rightPad("bat", 5, null)  = "bat  "
* StringUtils.rightPad("bat", 5, "")    = "bat  "

71.leftPad()

描述:与right对应,在字符串前补全。

* StringUtils.leftPad(null, *)   = null
* StringUtils.leftPad("", 3)= "   "
* StringUtils.leftPad("bat", 3)  = "bat"
* StringUtils.leftPad("bat", 5)  = "  bat"
* StringUtils.leftPad("bat", 1)  = "bat"
* StringUtils.leftPad("bat", -1) = "bat"

* StringUtils.leftPad(null, *, *)= null
* StringUtils.leftPad("", 3, 'z')= "zzz"
* StringUtils.leftPad("bat", 3, 'z')  = "bat"
* StringUtils.leftPad("bat", 5, 'z')  = "zzbat"
* StringUtils.leftPad("bat", 1, 'z')  = "bat"
* StringUtils.leftPad("bat", -1, 'z') = "bat"

* StringUtils.leftPad(null, *, *) = null
* StringUtils.leftPad("", 3, "z") = "zzz"
* StringUtils.leftPad("bat", 3, "yz")  = "bat"
* StringUtils.leftPad("bat", 5, "yz")  = "yzbat"
* StringUtils.leftPad("bat", 8, "yz")  = "yzyzybat"
* StringUtils.leftPad("bat", 1, "yz")  = "bat"
* StringUtils.leftPad("bat", -1, "yz") = "bat"
* StringUtils.leftPad("bat", 5, null)  = "  bat"
* StringUtils.leftPad("bat", 5, "")    = "  bat"

72.center()

描述1:返回一个字符串,长度为size,str位于新串中心,空格补齐。

* StringUtils.center(null, *)   = null
* StringUtils.center("", 4)= "    "
* StringUtils.center("ab", -1)  = "ab"
* StringUtils.center("ab", 4)   = " ab "
* StringUtils.center("abcd", 2) = "abcd"
* StringUtils.center("a", 4)    = " a  "

描述2:返回一个字符串,长度为size,str位于新串中心,padChar补齐。

* StringUtils.center(null, *, *)= null
* StringUtils.center("", 4, ' ')= "    "
* StringUtils.center("ab", -1, ' ')  = "ab"
* StringUtils.center("ab", 4, ' ')   = " ab "
* StringUtils.center("abcd", 2, ' ') = "abcd"
* StringUtils.center("a", 4, ' ')    = " a  "
* StringUtils.center("a", 4, 'y')    = "yayy"

描述3:返回一个字符串,长度为size,str位于新串中心,padStr补齐,padStr可拆分。

* StringUtils.center(null, *, *)= null
* StringUtils.center("", 4, " ")= "    "
* StringUtils.center("ab", -1, " ")  = "ab"
* StringUtils.center("ab", 4, " ")   = " ab "
* StringUtils.center("abcd", 2, " ") = "abcd"
* StringUtils.center("a", 4, " ")    = " a  "
* StringUtils.center("a", 4, "yz")   = "yayz"
* StringUtils.center("abc", 7, null) = "  abc  "
* StringUtils.center("abc", 7, "")   = "  abc  "

73.upperCase()

描述:将字符串转化为大写。

* StringUtils.upperCase(null)  = null
* StringUtils.upperCase("")    = ""
* StringUtils.upperCase("aBc") = "ABC"

74.lowerCase()

描述:将字符串转化为小写。

* StringUtils.lowerCase(null)  = null
* StringUtils.lowerCase("")    = ""
* StringUtils.lowerCase("aBc") = "abc"

75.capitalize()

描述:将字符串首字符转化为大写。

* StringUtils.capitalize(null)  = null
* StringUtils.capitalize("")    = ""
* StringUtils.capitalize("cat") = "Cat"
* StringUtils.capitalize("cAt") = "CAt"

76.uncapitalize()

描述:将字符串首字符转化为小写。

* StringUtils.uncapitalize(null)  = null
* StringUtils.uncapitalize("")    = ""
* StringUtils.uncapitalize("Cat") = "cat"
* StringUtils.uncapitalize("CAT") = "cAT"

77.swapCase()

描述:字符串大写转小写,小写转大写。

* StringUtils.swapCase(null)  = null
* StringUtils.swapCase("")    = ""
* StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone"

78.countMatches()

描述:计算字符序列str中字符序列sub的数量。

* StringUtils.countMatches("", *)    = 0
* StringUtils.countMatches("abba", null)  = 0
* StringUtils.countMatches("abba", "")    = 0
* StringUtils.countMatches("abba", "a")   = 2
* StringUtils.countMatches("abba", "ab")  = 1
* StringUtils.countMatches("abba", "xxx") = 0

79.reverse()

描述:反转字符串。

* StringUtils.reverse(null)  = null
* StringUtils.reverse("")    = ""
* StringUtils.reverse("bat") = "tab"

80.reverseDelimited()

描述:反转由特定字符分隔的字符串。

* StringUtils.reverseDelimited(null, *) = null
* StringUtils.reverseDelimited("", *)   = ""
* StringUtils.reverseDelimited("a.b.c", 'x') = "a.b.c"
* StringUtils.reverseDelimited("a.b.c", ".") = "c.b.a"

81.difference()

描述:返回str2跟str1比较特有的部分。

* StringUtils.difference(null, null) = null
* StringUtils.difference("", "") = ""
* StringUtils.difference("", "abc") = "abc"
* StringUtils.difference("abc", "") = ""
* StringUtils.difference("abc", "abc") = ""
* StringUtils.difference("abc", "ab") = ""
* StringUtils.difference("ab", "abxyz") = "xyz"
* StringUtils.difference("abcde", "abxyz") = "xyz"
* StringUtils.difference("abcde", "xyz") = "xyz"

82.indexOfDifference()

描述1:返回两个字符序列cs1、cs2开始不同的位置。

* StringUtils.indexOfDifference(null, null) = -1
* StringUtils.indexOfDifference("", "") = -1
* StringUtils.indexOfDifference("", "abc") = 0
* StringUtils.indexOfDifference("abc", "") = 0
* StringUtils.indexOfDifference("abc", "abc") = -1
* StringUtils.indexOfDifference("ab", "abxyz") = 2
* StringUtils.indexOfDifference("abcde", "abxyz") = 2
* StringUtils.indexOfDifference("abcde", "xyz") = 0

描述2:比较数组中所有的字符序列,并返回开始不同的位置。

* StringUtils.indexOfDifference(null) = -1
* StringUtils.indexOfDifference(new String[] {}) = -1
* StringUtils.indexOfDifference(new String[] {"abc"}) = -1
* StringUtils.indexOfDifference(new String[] {null, null}) = -1
* StringUtils.indexOfDifference(new String[] {"", ""}) = -1
* StringUtils.indexOfDifference(new String[] {"", null}) = 0
* StringUtils.indexOfDifference(new String[] {"abc", null, null}) = 0
* StringUtils.indexOfDifference(new String[] {null, null, "abc"}) = 0
* StringUtils.indexOfDifference(new String[] {"", "abc"}) = 0
* StringUtils.indexOfDifference(new String[] {"abc", ""}) = 0
* StringUtils.indexOfDifference(new String[] {"abc", "abc"}) = -1
* StringUtils.indexOfDifference(new String[] {"abc", "a"}) = 1
* StringUtils.indexOfDifference(new String[] {"ab", "abxyz"}) = 2
* StringUtils.indexOfDifference(new String[] {"abcde", "abxyz"}) = 2
* StringUtils.indexOfDifference(new String[] {"abcde", "xyz"}) = 0
* StringUtils.indexOfDifference(new String[] {"xyz", "abcde"}) = 0
* StringUtils.indexOfDifference(new String[] {"i am a machine", "i am a robot"}) = 7

83.toEncodedString()

描述:使用指定的编码,将字节数组转化为字符串。

本文地址:https://blog.csdn.net/qq_39150049/article/details/111957590