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

commons-lang3-StringUtils

程序员文章站 2022-09-27 18:49:57
字符串工具类abbreviate(String str, int maxWidth) 返回一个指定长度加省略号的字符串,maxWidth必须大于3StringUtils.abbreviate(null, *) = nullStringUtils.abbreviate("", 4) = ""Strin... ......

字符串工具类

abbreviate(string str, int maxwidth) 返回一个指定长度加省略号的字符串,maxwidth必须大于3

stringutils.abbreviate(null, *)      = null

stringutils.abbreviate("", 4)        = ""

stringutils.abbreviate("abcdefg", 6) = "abc..."

stringutils.abbreviate("abcdefg", 7) = "abcdefg"

stringutils.abbreviate("abcdefg", 8) = "abcdefg"

stringutils.abbreviate("abcdefg", 4) = "a..."

stringutils.abbreviate("abcdefg", 3) = illegalargumentexception

abbreviate(string str, int offset, int maxwidth) 返回一个指定长度加省略号的字符串,maxwidth必须大于3

abbreviate(string str, string abbrevmarker, int maxwidth) 返回一个自定义省略号的指定长度字符串,maxwidth必须大于3

stringutils.abbreviate(null, "...", *)      = null

stringutils.abbreviate("abcdefg", null, *)  = "abcdefg"

stringutils.abbreviate("", "...", 4)        = ""

stringutils.abbreviate("abcdefg", ".", 5)   = "abcd."

stringutils.abbreviate("abcdefg", ".", 7)   = "abcdefg"

stringutils.abbreviate("abcdefg", ".", 8)   = "abcdefg"

stringutils.abbreviate("abcdefg", "..", 4)  = "ab.."

stringutils.abbreviate("abcdefg", "..", 3)  = "a.."

stringutils.abbreviate("abcdefg", "..", 2)  = illegalargumentexception

stringutils.abbreviate("abcdefg", "...", 3) = illegalargumentexception

abbreviatemiddle(string str, string abbrevmarker, int maxwidth) 将字符串缩短到指定长度(length),字符串的中间部分用替换字符串(middle)显示

stringutils.abbreviatemiddle("abc", null, 0)      = "abc"

stringutils.abbreviatemiddle("abc", ".", 0)      = "abc"

stringutils.abbreviatemiddle("abc", ".", 3)      = "abc"

stringutils.abbreviatemiddle("abcdef", ".", 4)     = "ab.f"

appendifmissing(string str, charsequence suffix, charsequence... suffixes) 如果str不是以任何suffixes结尾,将字符串suffix拼接到字符串str后面

stringutils.appendifmissing(null, null) = null

stringutils.appendifmissing("abc", null) = "abc"

stringutils.appendifmissing("", "xyz") = "xyz"

stringutils.appendifmissing("abc", "xyz") = "abcxyz"

stringutils.appendifmissing("abcxyz", "xyz") = "abcxyz"

stringutils.appendifmissing("abcxyz", "xyz") = "abcxyzxyz"

appendifmissingignorecase(string str, charsequence suffix, charsequence... suffixes) 同上 不区分大小写

capitalize(string str) 将字符串第一个字符大写并返回

center(string str, int size) 用空格字符填充使字符串str位于长度为size的大字符串中间

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  "

center(string str, int size, char padchar) 用指定字符填充使字符串str位于长度为size的大字符串中间

chomp(string str) 删除字符串末尾的一个换行符,返回一个新的字符串(换行符"n", "r", or "rn")

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")        = ""

chop(string str) 删除字符串末尾的一个字符,返回一个新的字符串

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")        = ""

compare(string str1, string str2) 比较两个字符串,返回一个int值

str1等于str2(或都为空)返回0

str1小于str2返回小于0

str1大于str2返回大于0

 

stringutils.compare(null, null)   = 0

stringutils.compare(null , "a")   < 0

stringutils.compare("a", null)    > 0

stringutils.compare("abc", "abc") = 0

stringutils.compare("a", "b")     < 0

stringutils.compare("b", "a")     > 0

stringutils.compare("a", "b")     > 0

stringutils.compare("ab", "abc")  < 0

contains(charsequence seq, charsequence searchseq) 检查字符串中是否包含指定字符,返回boolean

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

containsany(charsequence cs, charsequence... searchcharsequences) 检查字符串中是否包含任一字符,返回boolean

stringutils.containsany(null, *)            = false

stringutils.containsany("", *)              = false

stringutils.containsany(*, null)            = false

stringutils.containsany(*, [])              = false

stringutils.containsany("abcd", "ab", null) = true

stringutils.containsany("abcd", "ab", "cd") = true

stringutils.containsany("abc", "d", "abc")  = true

containsnone(charsequence cs, string invalidchars) 检查字符串不包含指定字符,返回boolean

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

containsonly(charsequence cs, string validchars) 检查字符串只包含特定的字符,返回boolean

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

containswhitespace(charsequence seq) 检查字符串中是否包含空格字符,返回boolean

countmatches(charsequence str, charsequence sub) 检查字符串中出现指定字符的次数,返回一个int值

stringutils.countmatches(null, *)       = 0

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

defaultifblank(t str, t defaultstr) 如果字符串为null、空(""),或全是空格,将返回指定字符串,否则返回原值

stringutils.defaultifblank(null, "null")  = "null"

stringutils.defaultifblank("", "null")    = "null"

stringutils.defaultifblank(" ", "null")   = "null"

stringutils.defaultifblank("bat", "null") = "bat"

stringutils.defaultifblank("", null)      = null

defaultifempty(t str, t defaultstr) 如果字符串为null、空(""),将返回指定字符串,否则返回原值

stringutils.defaultifempty(null, "null")  = "null"

stringutils.defaultifempty("", "null")    = "null"

stringutils.defaultifempty(" ", "null")   = " "

stringutils.defaultifempty("bat", "null") = "bat"

stringutils.defaultifempty("", null)      = null

defaultstring(string str) 如果字符串为null,将返回空的字符串(""),否则返回原值

stringutils.defaultstring(null)  = ""

stringutils.defaultstring("")    = ""

stringutils.defaultstring("bat") = "bat"

defaultstring(string str, string defaultstr) 如果字符串为null,将返回指定字符,否则返回原值

stringutils.defaultstring(null, "null")  = "null"

stringutils.defaultstring("", "null")    = ""

stringutils.defaultstring("bat", "null") = "bat"

deletewhitespace(string str) 删除字符串中的空格字符,并返回新的字符串

stringutils.deletewhitespace(null)         = null

stringutils.deletewhitespace("")           = ""

stringutils.deletewhitespace("abc")        = "abc"

stringutils.deletewhitespace("   ab  c  ") = "abc"

difference(string str1, string str2) 比较两个字符串差异,并返回差异的字符,返回第二个字符串的剩余部分,这意味着“abc”和“ab”之间的区别是空字符串而不是“c”。

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"

endswith(charsequence str, charsequence suffix) 检查字符串是否以指定字符结尾,返回一个boolean

stringutils.endswith(null, null)      = true

stringutils.endswith(null, "def")     = false

stringutils.endswith("abcdef", null)  = false

stringutils.endswith("abcdef", "def") = true

stringutils.endswith("abcdef", "def") = false

stringutils.endswith("abcdef", "cde") = false

stringutils.endswith("abcdef", "")    = true

endswithany(charsequence sequence, charsequence... searchstrings) 检查字符串是否以指定字符数组结尾,返回一个boolean

stringutils.endswithany(null, null)      = false

stringutils.endswithany(null, new string[] {"abc"})  = false

stringutils.endswithany("abcxyz", null)     = false

stringutils.endswithany("abcxyz", new string[] {""}) = true

stringutils.endswithany("abcxyz", new string[] {"xyz"}) = true

stringutils.endswithany("abcxyz", new string[] {null, "xyz", "abc"}) = true

stringutils.endswithany("abcxyz", "def", "xyz") = true

stringutils.endswithany("abcxyz", "def", "xyz") = false

endswithignorecase(charsequence str, charsequence suffix) 检查字符串是否以指定字符(不区分大小写)结尾,返回一个boolean

stringutils.endswithignorecase(null, null)      = true

stringutils.endswithignorecase(null, "def")     = false

stringutils.endswithignorecase("abcdef", null)  = false

stringutils.endswithignorecase("abcdef", "def") = true

stringutils.endswithignorecase("abcdef", "def") = true

stringutils.endswithignorecase("abcdef", "cde") = false

equals(charsequence cs1, charsequence cs2) 比较两个字符串是否相等,返回一个boolean

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

equalsanyignorecase(charsequence string, charsequence... searchstrings) 比较两个字符串是否相等(不区分大小写),返回一个boolean

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

equalsany(charsequence string, charsequence... searchstrings) 比较字符串是否与指定字符串数组中某一值相等,返回一个boolean

stringutils.equalsany(null, (charsequence[]) null) = false

stringutils.equalsany(null, null, null)    = true

stringutils.equalsany(null, "abc", "def")  = false

stringutils.equalsany("abc", null, "def")  = false

stringutils.equalsany("abc", "abc", "def") = true

stringutils.equalsany("abc", "abc", "def") = false

equalsanyignorecase(charsequence string, charsequence... searchstrings) 比较字符串是否与指定字符串数组中某一值相等(不区分大小写),返回一个boolean

stringutils.equalsanyignorecase(null, (charsequence[]) null) = false

stringutils.equalsanyignorecase(null, null, null)    = true

stringutils.equalsanyignorecase(null, "abc", "def")  = false

stringutils.equalsanyignorecase("abc", null, "def")  = false

stringutils.equalsanyignorecase("abc", "abc", "def") = true

stringutils.equalsanyignorecase("abc", "abc", "def") = true

getcommonprefix(string... strs) 获取字符串数组元素公共字符,返回string

stringutils.getcommonprefix(null) = ""

stringutils.getcommonprefix(new string[] {}) = ""

stringutils.getcommonprefix(new string[] {"abc"}) = "abc"

stringutils.getcommonprefix(new string[] {null, null}) = ""

stringutils.getcommonprefix(new string[] {"", ""}) = ""

stringutils.getcommonprefix(new string[] {"", null}) = ""

stringutils.getcommonprefix(new string[] {"abc", null, null}) = ""

stringutils.getcommonprefix(new string[] {null, null, "abc"}) = ""

stringutils.getcommonprefix(new string[] {"", "abc"}) = ""

stringutils.getcommonprefix(new string[] {"abc", ""}) = ""

stringutils.getcommonprefix(new string[] {"abc", "abc"}) = "abc"

stringutils.getcommonprefix(new string[] {"abc", "a"}) = "a"

stringutils.getcommonprefix(new string[] {"ab", "abxyz"}) = "ab"

stringutils.getcommonprefix(new string[] {"abcde", "abxyz"}) = "ab"

stringutils.getcommonprefix(new string[] {"abcde", "xyz"}) = ""

stringutils.getcommonprefix(new string[] {"xyz", "abcde"}) = ""

stringutils.getcommonprefix(new string[] {"i am a machine", "i am a robot"}) = "i am a "

indexof(charsequence seq, charsequence searchseq) 检查指定字符在字符串中出现的位置,返回一个int值

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

indexofignorecase(charsequence seq, charsequence searchseq) 检查指定字符在字符串中出现的位置(不区分大小写),返回一个int值

isallblank(charsequence... css) 检查数组所有字符是否为null、empty、或全是空格字符,返回一个boolean

stringutils.isallblank(null)             = true

stringutils.isallblank(null, "foo")      = false

stringutils.isallblank(null, null)       = true

stringutils.isallblank("", "bar")        = false

stringutils.isallblank("bob", "")        = false

stringutils.isallblank("  bob  ", null)  = false

stringutils.isallblank(" ", "bar")       = false

stringutils.isallblank("foo", "bar")     = false

stringutils.isallblank(new string[] {})  = true

isallempty(charsequence... css) 检查数组所有字符是否为null、empty,返回一个boolean

stringutils.isallempty(null)             = true

stringutils.isallempty(null, "")         = true

stringutils.isallempty(new string[] {})  = true

stringutils.isallempty(null, "foo")      = false

stringutils.isallempty("", "bar")        = false

stringutils.isallempty("bob", "")        = false

stringutils.isallempty("  bob  ", null)  = false

stringutils.isallempty(" ", "bar")       = false

stringutils.isallempty("foo", "bar")     = false

isalllowercase(charsequence cs) 检查字符串中所有字符是否是小写,返回一个boolean

isalluppercase(charsequence cs) 检查字符串中所有字符是否是大写,返回一个boolean

isanyblank(charsequence... css) 检查数组中字符串是否有一个为null、empty或全是空格字符,返回一个boolean

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(new string[] {})  = false

stringutils.isanyblank(new string[]{""}) = true

stringutils.isanyblank("foo", "bar")     = false

isanyempty(charsequence... css) 检查数组中字符串是否有一个为null、empty,返回一个boolean

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

stringutils.isanyempty(new string[]{})   = false

stringutils.isanyempty(new string[]{""}) = true

isblank(charsequence cs) 检查字符串是否为null、empty或空格字符,返回一个boolean

stringutils.isblank(null)      = true

stringutils.isblank("")        = true

stringutils.isblank(" ")       = true

stringutils.isblank("bob")     = false

stringutils.isblank("  bob  ") = false

isempty(charsequence cs) 检查字符串是否为null、empty,返回一个boolean

stringutils.isempty(null)      = true

stringutils.isempty("")        = true

stringutils.isempty(" ")       = false

stringutils.isempty("bob")     = false

stringutils.isempty("  bob  ") = false

isnotblank(charsequence cs) 检查字符串是否不为null、empty或空格字符,返回一个boolean

isnotempty(charsequence cs) 检查字符串是否不为null、empty,返回一个boolean

isnumeric(charsequence cs) 检查字符串是否是数字,返回一个boolean

stringutils.isnumeric(null)   = false

stringutils.isnumeric("")     = false

stringutils.isnumeric("  ")   = false

stringutils.isnumeric("123")  = true

stringutils.isnumeric("१२३")  = true

stringutils.isnumeric("12 3") = false

stringutils.isnumeric("ab2c") = false

stringutils.isnumeric("12-3") = false

stringutils.isnumeric("12.3") = false

stringutils.isnumeric("-123") = false

stringutils.isnumeric("+123") = false

iswhitespace(charsequence cs) 检查字符串是否是空格字符,返回一个boolean

stringutils.iswhitespace(null)   = false

stringutils.iswhitespace("")     = true

stringutils.iswhitespace("  ")   = true

stringutils.iswhitespace("abc")  = false

stringutils.iswhitespace("ab2c") = false

stringutils.iswhitespace("ab-c") = false

join(byte[] array, char separator) 将字节数组转换成string,以指定字符分隔

stringutils.join(null, *)               = null

stringutils.join([], *)                 = ""

stringutils.join([null], *)             = ""

stringutils.join([1, 2, 3], ';')  = "1;2;3"

stringutils.join([1, 2, 3], null) = "123"

char、double、float、int、long、short、object、t同理

joinwith(string separator, object... objects) 将多个元素已指定字符分隔拼接成string

stringutils.joinwith(",", {"a", "b"})        = "a,b"

stringutils.joinwith(",", {"a", "b",""})     = "a,b,"

stringutils.joinwith(",", {"a", null, "b"})  = "a,,b"

stringutils.joinwith(null, {"a", "b"})       = "ab"

lastindexof(charsequence seq, charsequence searchseq) 获取指定字符在字符串中的最后一个索引位置

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

left(string str, int len) 返回从左边开始指定大小的字符串

stringutils.left(null, *)    = null

stringutils.left(*, -ve)     = ""

stringutils.left("", *)      = ""

stringutils.left("abc", 0)   = ""

stringutils.left("abc", 2)   = "ab"

stringutils.left("abc", 4)   = "abc"

right(string str, int len) 同上相反

length(charsequence cs) 获取字符串大小,返回一个int

lowercase(string str) 将字符串转换为小写,返回一个string

stringutils.lowercase(null)  = null

stringutils.lowercase("")    = ""

stringutils.lowercase("abc") = "abc"

uppercase(string str) 同上相反

mid(string str, int pos, int len) 获取字符串指定位置区间的字符,返回一个string

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"

overlay(string str, string overlay, int start, int end) 在字符串位置区间插入指定字符,返回一个string

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"

prependifmissing(string str, charsequence prefix, charsequence... prefixes) 在字符串最左边插入指定字符,如果已存在,将不插入,返回一个string

stringutils.prependifmissing(null, null) = null

stringutils.prependifmissing("abc", null) = "abc"

stringutils.prependifmissing("", "xyz") = "xyz"

stringutils.prependifmissing("abc", "xyz") = "xyzabc"

stringutils.prependifmissing("xyzabc", "xyz") = "xyzabc"

stringutils.prependifmissing("xyzabc", "xyz") = "xyzxyzabc"

prependifmissingignorecase(string str, charsequence prefix, charsequence... prefixes) 同上,只是不区分大小写

remove(string str, char remove) 删除字符串中指定字符,返回一个string

stringutils.remove(null, *)       = null

stringutils.remove("", *)         = ""

stringutils.remove("queued", 'u') = "qeed"

stringutils.remove("queued", 'z') = "queued"

removeignorecase(string str, string remove) 同上,只是不区分大小写

removeall(string text, string regex) 根据匹配规则删除所有字符,返回一个string

stringutils.removeall(null, *)      = null

stringutils.removeall("any", null)  = "any"

stringutils.removeall("any", "")    = "any"

stringutils.removeall("any", ".*")  = ""

stringutils.removeall("any", ".+")  = ""

stringutils.removeall("abc", ".?")  = ""

stringutils.removeall("a<__>\n<__>b", "<.*>")      = "a\nb"

stringutils.removeall("a<__>\n<__>b", "(?s)<.*>")  = "ab"

stringutils.removeall("abcabc123abc", "[a-z]")     = "abc123"

removeend(string str, string remove) 删除字符串结尾指定字符,返回一个string

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"

removestart(string str, string remove) 同上相反

removeendignorecase(string str, string remove) 同上,只是不区分大小写

removefirst(string text, string regex) 根据匹配规则删除第一次出现的字符,返回一个string

stringutils.removefirst(null, *)      = null

stringutils.removefirst("any", null)  = "any"

stringutils.removefirst("any", "")    = "any"

stringutils.removefirst("any", ".*")  = ""

stringutils.removefirst("any", ".+")  = ""

stringutils.removefirst("abc", ".?")  = "bc"

stringutils.removefirst("a<__>\n<__>b", "<.*>")      = "a\n<__>b"

stringutils.removefirst("a<__>\n<__>b", "(?s)<.*>")  = "ab"

stringutils.removefirst("abcabc123", "[a-z]")          = "abcbc123"

stringutils.removefirst("abcabc123abc", "[a-z]+")      = "abc123abc"

repeat(string str, int repeat) 将字符重复指定次数拼接成新的字符串,返回一个string

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) = ""

replace(string text, string searchstring, string replacement) 用replacement替换字符串中的所有searchstring,返回一个string

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"

reverse(string str) 将字符串反转,返回一个string

stringutils.reverse(null)  = null

stringutils.reverse("")    = ""

stringutils.reverse("bat") = "tab"

reversedelimited(string str, char separatorchar) 将字符串指定分隔符出的字符反转

stringutils.reversedelimited(null, *)      = null

  stringutils.reversedelimited("", *)        = ""

  stringutils.reversedelimited("a.b.c", 'x') = "a.b.c"

  stringutils.reversedelimited("a.b.c", ".") = "c.b.a"

split(string str, string separatorchars) 将字符串以指定字符分隔,返回数组

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"]

substring(string str, int start) 将字符串从指定位置区间截取,返回string

swapcase(string str) 将字符串大小写互转,返回一个string

stringutils.swapcase(null)                 = null

stringutils.swapcase("")                   = ""

stringutils.swapcase("the dog has a bone") = "the dog has a bone"

toencodedstring(byte[] bytes, charset charset) 将字符串转为指定编码格式,返回一个string

trim(string str) 去除字符串空格

trimtoempty(string str) 去除字符串空格,null转为empty,返回一个string

stringutils.trimtoempty(null)          = ""

stringutils.trimtoempty("")            = ""

stringutils.trimtoempty("     ")       = ""

stringutils.trimtoempty("abc")         = "abc"

stringutils.trimtoempty("    abc    ") = "abc"

---------------------

来源:csdn

原文: