类 StringUtil
java.lang.Object
org.apache.commons.lang3.StringUtils
io.github.mangocrisp.spring.taybct.tool.core.util.StringUtil
public class StringUtil
extends org.apache.commons.lang3.StringUtils
字符串工具类
- 从以下版本开始:
- 1.0.0
-
字段概要
字段从类继承的字段 org.apache.commons.lang3.StringUtils
CR, EMPTY, LF, SPACE
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static StringBuilder
appendBuilder
(StringBuilder sb, CharSequence... strs) 创建StringBuilder对象static StringBuilder
builder()
创建StringBuilder对象static StringBuilder
builder
(int capacity) 创建StringBuilder对象static StringBuilder
builder
(CharSequence... strs) 创建StringBuilder对象static String
cleanChars
(String txt) 清理字符串,清理出某些不可见字符static boolean
contains
(CharSequence str, char searchChar) 指定字符是否在字符串中出现过static boolean
containsIgnoreCase
(CharSequence str, CharSequence testStr) 是否包含特定字符,忽略大小写,如果给定两个参数都为null
,返回truestatic int
count
(CharSequence content, char charForSearch) 统计指定内容中包含指定字符的数量static String
加密脱敏字符串默认保留一个字符(头尾)static String
static String
static String
static String
static String
static String
加密字符串static String
static String
static boolean
equals
(CharSequence str1, CharSequence str2) 比较两个字符串(大小写敏感)。static boolean
equals
(CharSequence str1, CharSequence str2, boolean ignoreCase) 比较两个字符串是否相等。static boolean
equalsIgnoreCase
(CharSequence str1, CharSequence str2) 比较两个字符串(大小写不敏感)。根据传入的字符串,输出字符串所有大小写组合集合static StringReader
getReader
(CharSequence str) 获得StringReaderstatic StringWriter
获得StringWriterstatic String
humpToLine
(String para) 驼峰转横线static String
humpToUnderline
(String para) 驼峰转下划线static String
indexedFormat
(CharSequence pattern, Object... arguments) 有序的格式化文本,使用{number}做为占位符
例:
通常使用:format("this is {0} for {1}", "a", "b") =》 this is a for bstatic int
indexOf
(CharSequence str, char searchChar) 指定范围内查找指定字符static int
indexOf
(CharSequence str, char searchChar, int start) 指定范围内查找指定字符static int
indexOf
(CharSequence str, char searchChar, int start, int end) 指定范围内查找指定字符static int
indexOf
(CharSequence str, CharSequence searchStr, int fromIndex, boolean ignoreCase) 指定范围内反向查找字符串static int
indexOfIgnoreCase
(CharSequence str, CharSequence searchStr) 指定范围内查找字符串,忽略大小写static int
indexOfIgnoreCase
(CharSequence str, CharSequence searchStr, int fromIndex) 指定范围内查找字符串static boolean
isSubEquals
(CharSequence str1, int start1, CharSequence str2, int start2, int length, boolean ignoreCase) 截取两个字符串的不同部分(长度一致),判断截取的子串是否相同
任意一个字符串为null返回falsestatic int
lastIndexOf
(CharSequence str, CharSequence searchStr, int fromIndex, boolean ignoreCase) 指定范围内查找字符串static int
lastIndexOfIgnoreCase
(CharSequence str, CharSequence searchStr) 指定范围内查找字符串,忽略大小写static int
lastIndexOfIgnoreCase
(CharSequence str, CharSequence searchStr, int fromIndex) 指定范围内查找字符串,忽略大小写static String
lineToHump
(String para) 横线转驼峰static String
lowerFirst
(String str) 首字母变小写static int
ordinalIndexOf
(String str, String searchStr, int ordinal) 返回字符串 searchStr 在字符串 str 中第 ordinal 次出现的位置。static String
生成uuidstatic String
removePrefix
(CharSequence str, CharSequence prefix) 去掉指定前缀static String
removePrefixIgnoreCase
(CharSequence str, CharSequence prefix) 忽略大小写去掉指定前缀static String
removeSufAndLowerFirst
(CharSequence str, CharSequence suffix) 去掉指定后缀,并小写首字母static String
removeSuffix
(CharSequence str, CharSequence suffix) 去掉指定后缀static String
removeSuffixIgnoreCase
(CharSequence str, CharSequence suffix) 忽略大小写去掉指定后缀static String
sub
(CharSequence str, int fromIndex, int toIndex) 改进JDK subString
index从0开始计算,最后一个字符为-1
如果from和to位置一样,返回 ""
如果from或to为负数,则按照length从后向前数位置,如果绝对值大于字符串长度,则from归到0,to归到length
如果经过修正的index中from大于to,则互换from和to example:
abcdefgh 2 3 =》 c
abcdefgh 2 -3 =》 cdestatic String
subAfter
(CharSequence string, CharSequence separator, boolean isLastSeparator) 截取分隔字符串之后的字符串,不包括分隔字符串
如果给定的字符串为空串(null或""),返回原字符串
如果分隔字符串为空串(null或""),则返回空串,如果分隔字符串未找到,返回空串static String
subBefore
(CharSequence string, CharSequence separator, boolean isLastSeparator) 截取分隔字符串之前的字符串,不包括分隔字符串
如果给定的字符串为空串(null或"")或者分隔字符串为null,返回原字符串
如果分隔字符串为空串"",则返回空串,如果分隔字符串未找到,返回原字符串static String
subBetween
(CharSequence str, CharSequence beforeAndAfter) 截取指定字符串中间部分,不包括标识字符串static String
subBetween
(CharSequence str, CharSequence before, CharSequence after) 截取指定字符串中间部分,不包括标识字符串static String
subPre
(CharSequence string, int toIndex) 切割指定位置之前部分的字符串static String
subSuf
(CharSequence string, int fromIndex) 切割指定位置之后部分的字符串static String
underlineToHump
(String para) 下划线转驼峰static String
upperFirst
(String str) 首字母变大写从类继承的方法 org.apache.commons.lang3.StringUtils
abbreviate, abbreviate, abbreviate, abbreviate, abbreviateMiddle, appendIfMissing, appendIfMissingIgnoreCase, capitalize, center, center, center, chomp, chomp, chop, compare, compare, compareIgnoreCase, compareIgnoreCase, contains, contains, containsAny, containsAny, containsAny, containsAnyIgnoreCase, containsNone, containsNone, containsOnly, containsOnly, containsWhitespace, countMatches, countMatches, defaultIfBlank, defaultIfEmpty, defaultString, defaultString, deleteWhitespace, difference, endsWith, endsWithAny, endsWithIgnoreCase, equalsAny, equalsAnyIgnoreCase, firstNonBlank, firstNonEmpty, getBytes, getBytes, getCommonPrefix, getDigits, getFuzzyDistance, getIfBlank, getIfEmpty, getJaroWinklerDistance, getLevenshteinDistance, getLevenshteinDistance, indexOf, indexOf, indexOf, indexOf, indexOfAny, indexOfAny, indexOfAny, indexOfAnyBut, indexOfAnyBut, indexOfDifference, indexOfDifference, isAllBlank, isAllEmpty, isAllLowerCase, isAllUpperCase, isAlpha, isAlphanumeric, isAlphanumericSpace, isAlphaSpace, isAnyBlank, isAnyEmpty, isAsciiPrintable, isBlank, isEmpty, isMixedCase, isNoneBlank, isNoneEmpty, isNotBlank, isNotEmpty, isNumeric, isNumericSpace, isWhitespace, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, joinWith, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexOfAny, lastOrdinalIndexOf, left, leftPad, leftPad, leftPad, length, lowerCase, lowerCase, mid, normalizeSpace, ordinalIndexOf, overlay, prependIfMissing, prependIfMissingIgnoreCase, remove, remove, removeAll, removeEnd, removeEndIgnoreCase, removeFirst, removeIgnoreCase, removePattern, removeStart, removeStart, removeStartIgnoreCase, repeat, repeat, repeat, replace, replace, replaceAll, replaceChars, replaceChars, replaceEach, replaceEachRepeatedly, replaceFirst, replaceIgnoreCase, replaceIgnoreCase, replaceOnce, replaceOnceIgnoreCase, replacePattern, reverse, reverseDelimited, right, rightPad, rightPad, rightPad, rotate, split, split, split, split, splitByCharacterType, splitByCharacterTypeCamelCase, splitByWholeSeparator, splitByWholeSeparator, splitByWholeSeparatorPreserveAllTokens, splitByWholeSeparatorPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, startsWith, startsWithAny, startsWithIgnoreCase, strip, strip, stripAccents, stripAll, stripAll, stripEnd, stripStart, stripToEmpty, stripToNull, substring, substring, substringAfter, substringAfter, substringAfterLast, substringAfterLast, substringBefore, substringBefore, substringBeforeLast, substringBetween, substringBetween, substringsBetween, swapCase, toCodePoints, toEncodedString, toRootLowerCase, toRootUpperCase, toString, trim, trimToEmpty, trimToNull, truncate, truncate, uncapitalize, unwrap, unwrap, upperCase, upperCase, valueOf, wrap, wrap, wrapIfMissing, wrapIfMissing
-
字段详细资料
-
INDEX_NOT_FOUND
public static final int INDEX_NOT_FOUND- 另请参阅:
-
-
构造器详细资料
-
StringUtil
public StringUtil()
-
-
方法详细资料
-
encrypt
-
encrypt
-
encrypt
-
encrypt
-
encrypt
-
encrypt
-
encrypt
加密脱敏字符串默认保留一个字符(头尾)- 参数:
input
- 输入字符串- 从以下版本开始:
- 1.0.0
-
encrypt
加密字符串- 参数:
input
- 输入字符串begin
- 头保留end
- 尾保留maxChar
- 最大加密字符长度chr
- 加密字符- 从以下版本开始:
- 1.0.0
-
encrypt
-
randomUUID
生成uuid- 从以下版本开始:
- 1.0.0
-
cleanChars
清理字符串,清理出某些不可见字符- 参数:
txt
- 字符串- 从以下版本开始:
- 1.0.0
-
indexedFormat
有序的格式化文本,使用{number}做为占位符
例:
通常使用:format("this is {0} for {1}", "a", "b") =》 this is a for b- 参数:
pattern
- 文本格式arguments
- 参数- 返回:
- 格式化后的文本
-
contains
指定字符是否在字符串中出现过- 参数:
str
- 字符串searchChar
- 被查找的字符- 返回:
- 是否包含
- 从以下版本开始:
- 1.0.0
-
containsIgnoreCase
是否包含特定字符,忽略大小写,如果给定两个参数都为null
,返回true- 参数:
str
- 被检测字符串testStr
- 被测试是否包含的字符串- 返回:
- 是否包含
- 从以下版本开始:
- 1.0.0
-
sub
改进JDK subString
index从0开始计算,最后一个字符为-1
如果from和to位置一样,返回 ""
如果from或to为负数,则按照length从后向前数位置,如果绝对值大于字符串长度,则from归到0,to归到length
如果经过修正的index中from大于to,则互换from和to example:
abcdefgh 2 3 =》 c
abcdefgh 2 -3 =》 cde- 参数:
str
- StringfromIndex
- 开始的index(包括)toIndex
- 结束的index(不包括)- 返回:
- 字串
- 从以下版本开始:
- 1.0.0
-
subBefore
public static String subBefore(CharSequence string, CharSequence separator, boolean isLastSeparator) 截取分隔字符串之前的字符串,不包括分隔字符串
如果给定的字符串为空串(null或"")或者分隔字符串为null,返回原字符串
如果分隔字符串为空串"",则返回空串,如果分隔字符串未找到,返回原字符串栗子:
StringUtil.subBefore(null, *) = null StringUtil.subBefore("", *) = "" StringUtil.subBefore("abc", "a") = "" StringUtil.subBefore("abcba", "b") = "a" StringUtil.subBefore("abc", "c") = "ab" StringUtil.subBefore("abc", "d") = "abc" StringUtil.subBefore("abc", "") = "" StringUtil.subBefore("abc", null) = "abc"
- 参数:
string
- 被查找的字符串separator
- 分隔字符串(不包括)isLastSeparator
- 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个- 返回:
- 切割后的字符串
- 从以下版本开始:
- 1.0.0
-
subAfter
截取分隔字符串之后的字符串,不包括分隔字符串
如果给定的字符串为空串(null或""),返回原字符串
如果分隔字符串为空串(null或""),则返回空串,如果分隔字符串未找到,返回空串栗子:
StringUtil.subAfter(null, *) = null StringUtil.subAfter("", *) = "" StringUtil.subAfter(*, null) = "" StringUtil.subAfter("abc", "a") = "bc" StringUtil.subAfter("abcba", "b") = "cba" StringUtil.subAfter("abc", "c") = "" StringUtil.subAfter("abc", "d") = "" StringUtil.subAfter("abc", "") = "abc"
- 参数:
string
- 被查找的字符串separator
- 分隔字符串(不包括)isLastSeparator
- 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个- 返回:
- 切割后的字符串
- 从以下版本开始:
- 1.0.0
-
subBetween
截取指定字符串中间部分,不包括标识字符串
栗子:
StringUtil.subBetween("wx[b]yz", "[", "]") = "b" StringUtil.subBetween(null, *, *) = null StringUtil.subBetween(*, null, *) = null StringUtil.subBetween(*, *, null) = null StringUtil.subBetween("", "", "") = "" StringUtil.subBetween("", "", "]") = null StringUtil.subBetween("", "[", "]") = null StringUtil.subBetween("yabcz", "", "") = "" StringUtil.subBetween("yabcz", "y", "z") = "abc" StringUtil.subBetween("yabczyabcz", "y", "z") = "abc"
- 参数:
str
- 被切割的字符串before
- 截取开始的字符串标识after
- 截取到的字符串标识- 返回:
- 截取后的字符串
- 从以下版本开始:
- 1.0.0
-
subBetween
截取指定字符串中间部分,不包括标识字符串
栗子:
StringUtil.subBetween(null, *) = null StringUtil.subBetween("", "") = "" StringUtil.subBetween("", "tag") = null StringUtil.subBetween("tagabctag", null) = null StringUtil.subBetween("tagabctag", "") = "" StringUtil.subBetween("tagabctag", "tag") = "abc"
- 参数:
str
- 被切割的字符串beforeAndAfter
- 截取开始和结束的字符串标识- 返回:
- 截取后的字符串
- 从以下版本开始:
- 1.0.0
-
removePrefix
去掉指定前缀- 参数:
str
- 字符串prefix
- 前缀- 返回:
- 切掉后的字符串,若前缀不是 preffix, 返回原字符串
- 从以下版本开始:
- 1.0.0
-
removePrefixIgnoreCase
忽略大小写去掉指定前缀- 参数:
str
- 字符串prefix
- 前缀- 返回:
- 切掉后的字符串,若前缀不是 prefix, 返回原字符串
-
removeSuffix
去掉指定后缀- 参数:
str
- 字符串suffix
- 后缀- 返回:
- 切掉后的字符串,若后缀不是 suffix, 返回原字符串
-
removeSufAndLowerFirst
去掉指定后缀,并小写首字母- 参数:
str
- 字符串suffix
- 后缀- 返回:
- 切掉后的字符串,若后缀不是 suffix, 返回原字符串
-
removeSuffixIgnoreCase
忽略大小写去掉指定后缀- 参数:
str
- 字符串suffix
- 后缀- 返回:
- 切掉后的字符串,若后缀不是 suffix, 返回原字符串
-
lowerFirst
首字母变小写- 参数:
str
- 字符串- 返回:
- {String}
-
upperFirst
首字母变大写- 参数:
str
- 字符串- 返回:
- {String}
-
subPre
切割指定位置之前部分的字符串- 参数:
string
- 字符串toIndex
- 切割到的位置(不包括)- 返回:
- 切割后的剩余的前半部分字符串
-
subSuf
切割指定位置之后部分的字符串- 参数:
string
- 字符串fromIndex
- 切割开始的位置(包括)- 返回:
- 切割后后剩余的后半部分字符串
-
indexOf
指定范围内查找指定字符- 参数:
str
- 字符串searchChar
- 被查找的字符- 返回:
- 位置
-
indexOf
指定范围内查找指定字符- 参数:
str
- 字符串searchChar
- 被查找的字符start
- 起始位置,如果小于0,从0开始查找- 返回:
- 位置
-
indexOf
指定范围内查找指定字符- 参数:
str
- 字符串searchChar
- 被查找的字符start
- 起始位置,如果小于0,从0开始查找end
- 终止位置,如果超过str.length()则默认查找到字符串末尾- 返回:
- 位置
-
indexOfIgnoreCase
指定范围内查找字符串,忽略大小写
StringUtil.indexOfIgnoreCase(null, *, *) = -1 StringUtil.indexOfIgnoreCase(*, null, *) = -1 StringUtil.indexOfIgnoreCase("", "", 0) = 0 StringUtil.indexOfIgnoreCase("aabaabaa", "A", 0) = 0 StringUtil.indexOfIgnoreCase("aabaabaa", "B", 0) = 2 StringUtil.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1 StringUtil.indexOfIgnoreCase("aabaabaa", "B", 3) = 5 StringUtil.indexOfIgnoreCase("aabaabaa", "B", 9) = -1 StringUtil.indexOfIgnoreCase("aabaabaa", "B", -1) = 2 StringUtil.indexOfIgnoreCase("aabaabaa", "", 2) = 2 StringUtil.indexOfIgnoreCase("abc", "", 9) = -1
- 参数:
str
- 字符串searchStr
- 需要查找位置的字符串- 返回:
- 位置
- 从以下版本开始:
- 1.0.0
-
indexOfIgnoreCase
指定范围内查找字符串StringUtil.indexOfIgnoreCase(null, *, *) = -1 StringUtil.indexOfIgnoreCase(*, null, *) = -1 StringUtil.indexOfIgnoreCase("", "", 0) = 0 StringUtil.indexOfIgnoreCase("aabaabaa", "A", 0) = 0 StringUtil.indexOfIgnoreCase("aabaabaa", "B", 0) = 2 StringUtil.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1 StringUtil.indexOfIgnoreCase("aabaabaa", "B", 3) = 5 StringUtil.indexOfIgnoreCase("aabaabaa", "B", 9) = -1 StringUtil.indexOfIgnoreCase("aabaabaa", "B", -1) = 2 StringUtil.indexOfIgnoreCase("aabaabaa", "", 2) = 2 StringUtil.indexOfIgnoreCase("abc", "", 9) = -1
- 参数:
str
- 字符串searchStr
- 需要查找位置的字符串fromIndex
- 起始位置- 返回:
- 位置
- 从以下版本开始:
- 1.0.0
-
indexOf
public static int indexOf(CharSequence str, CharSequence searchStr, int fromIndex, boolean ignoreCase) 指定范围内反向查找字符串- 参数:
str
- 字符串searchStr
- 需要查找位置的字符串fromIndex
- 起始位置ignoreCase
- 是否忽略大小写- 返回:
- 位置
- 从以下版本开始:
- 1.0.0
-
lastIndexOfIgnoreCase
指定范围内查找字符串,忽略大小写- 参数:
str
- 字符串searchStr
- 需要查找位置的字符串- 返回:
- 位置
- 从以下版本开始:
- 1.0.0
-
lastIndexOfIgnoreCase
指定范围内查找字符串,忽略大小写- 参数:
str
- 字符串searchStr
- 需要查找位置的字符串fromIndex
- 起始位置,从后往前计数- 返回:
- 位置
- 从以下版本开始:
- 1.0.0
-
lastIndexOf
public static int lastIndexOf(CharSequence str, CharSequence searchStr, int fromIndex, boolean ignoreCase) 指定范围内查找字符串- 参数:
str
- 字符串searchStr
- 需要查找位置的字符串fromIndex
- 起始位置,从后往前计数ignoreCase
- 是否忽略大小写- 返回:
- 位置
- 从以下版本开始:
- 1.0.0
-
ordinalIndexOf
返回字符串 searchStr 在字符串 str 中第 ordinal 次出现的位置。
此方法来自:Apache-Commons-Lang栗子(*代表任意字符):
StringUtil.ordinalIndexOf(null, *, *) = -1 StringUtil.ordinalIndexOf(*, null, *) = -1 StringUtil.ordinalIndexOf("", "", *) = 0 StringUtil.ordinalIndexOf("aabaabaa", "a", 1) = 0 StringUtil.ordinalIndexOf("aabaabaa", "a", 2) = 1 StringUtil.ordinalIndexOf("aabaabaa", "b", 1) = 2 StringUtil.ordinalIndexOf("aabaabaa", "b", 2) = 5 StringUtil.ordinalIndexOf("aabaabaa", "ab", 1) = 1 StringUtil.ordinalIndexOf("aabaabaa", "ab", 2) = 4 StringUtil.ordinalIndexOf("aabaabaa", "", 1) = 0 StringUtil.ordinalIndexOf("aabaabaa", "", 2) = 0
- 参数:
str
- 被检查的字符串,可以为nullsearchStr
- 被查找的字符串,可以为nullordinal
- 第几次出现的位置- 返回:
- 查找到的位置
- 从以下版本开始:
- 1.0.0
-
isSubEquals
public static boolean isSubEquals(CharSequence str1, int start1, CharSequence str2, int start2, int length, boolean ignoreCase) 截取两个字符串的不同部分(长度一致),判断截取的子串是否相同
任意一个字符串为null返回false- 参数:
str1
- 第一个字符串start1
- 第一个字符串开始的位置str2
- 第二个字符串start2
- 第二个字符串开始的位置length
- 截取长度ignoreCase
- 是否忽略大小写- 返回:
- 子串是否相同
- 从以下版本开始:
- 1.0.0
-
equals
比较两个字符串(大小写敏感)。equalsIgnoreCase(null, null) = true equalsIgnoreCase(null, "abc") = false equalsIgnoreCase("abc", null) = false equalsIgnoreCase("abc", "abc") = true equalsIgnoreCase("abc", "ABC") = true
- 参数:
str1
- 要比较的字符串1str2
- 要比较的字符串2- 返回:
- 如果两个字符串相同,或者都是
null
,则返回true
-
equalsIgnoreCase
比较两个字符串(大小写不敏感)。equalsIgnoreCase(null, null) = true equalsIgnoreCase(null, "abc") = false equalsIgnoreCase("abc", null) = false equalsIgnoreCase("abc", "abc") = true equalsIgnoreCase("abc", "ABC") = true
- 参数:
str1
- 要比较的字符串1str2
- 要比较的字符串2- 返回:
- 如果两个字符串相同,或者都是
null
,则返回true
-
equals
比较两个字符串是否相等。- 参数:
str1
- 要比较的字符串1str2
- 要比较的字符串2ignoreCase
- 是否忽略大小写- 返回:
- 如果两个字符串相同,或者都是
null
,则返回true
- 从以下版本开始:
- 1.0.0
-
builder
创建StringBuilder对象- 返回:
- StringBuilder对象
-
builder
创建StringBuilder对象- 参数:
capacity
- 初始大小- 返回:
- StringBuilder对象
-
builder
创建StringBuilder对象- 参数:
strs
- 初始字符串列表- 返回:
- StringBuilder对象
-
appendBuilder
创建StringBuilder对象- 参数:
sb
- 初始StringBuilderstrs
- 初始字符串列表- 返回:
- StringBuilder对象
-
getReader
获得StringReader- 参数:
str
- 字符串- 返回:
- StringReader
-
getWriter
获得StringWriter- 返回:
- StringWriter
-
count
统计指定内容中包含指定字符的数量- 参数:
content
- 内容charForSearch
- 被统计的字符- 返回:
- 包含数量
-
underlineToHump
下划线转驼峰- 参数:
para
- 字符串- 返回:
- String
-
humpToUnderline
驼峰转下划线- 参数:
para
- 字符串- 返回:
- String
-
lineToHump
横线转驼峰- 参数:
para
- 字符串- 返回:
- String
-
humpToLine
驼峰转横线- 参数:
para
- 字符串- 返回:
- String
-
getArrayListByString
根据传入的字符串,输出字符串所有大小写组合集合- 参数:
str
- 输入字符串- 返回:
- 所有组合
-