public class CharSequenceUtil extends Object
CharSequence
相关工具类封装Modifier and Type | Field and Description |
---|---|
static String |
EMPTY
字符串常量:空字符串
"" |
static int |
INDEX_NOT_FOUND |
static String |
NULL
字符串常量:
"null" 注意:{@code "null" ! |
static String |
SPACE
字符串常量:空格符
" " |
Constructor and Description |
---|
CharSequenceUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
addPrefixIfNot(CharSequence str,
CharSequence prefix)
如果给定字符串不是以prefix开头的,在开头补充 prefix
|
static String |
addSuffixIfNot(CharSequence str,
CharSequence suffix)
如果给定字符串不是以suffix结尾的,在尾部补充 suffix
|
static String |
appendIfMissing(CharSequence str,
CharSequence suffix,
boolean ignoreCase,
CharSequence... testSuffixes)
如果给定字符串不是以给定的一个或多个字符串为结尾,则在尾部添加结尾字符串
|
static String |
appendIfMissing(CharSequence str,
CharSequence suffix,
CharSequence... suffixes)
如果给定字符串不是以给定的一个或多个字符串为结尾,则在尾部添加结尾字符串
不忽略大小写 |
static String |
appendIfMissingIgnoreCase(CharSequence str,
CharSequence suffix,
CharSequence... suffixes)
如果给定字符串不是以给定的一个或多个字符串为结尾,则在尾部添加结尾字符串
忽略大小写 |
static String |
blankToDefault(CharSequence str,
String defaultStr)
如果字符串是
null 或者""或者空白,则返回指定默认字符串,否则返回字符串本身。 |
static String |
brief(CharSequence str,
int maxLength)
将给定字符串,变成 "xxx...xxx" 形式的字符串
abcdefgh 9 -》 abcdefgh
abcdefgh 8 -》 abcdefgh
abcdefgh 7 -》 ab...gh
abcdefgh 6 -》 ab...h
abcdefgh 5 -》 a...h
abcdefgh 4 -》 a..h
abcdefgh 3 -》 a.h
abcdefgh 2 -》 a.
|
static StringBuilder |
builder(CharSequence... strs)
创建StringBuilder对象
|
static ByteBuffer |
byteBuffer(CharSequence str,
String charset)
字符串转换为byteBuffer
|
static int |
byteLength(CharSequence cs,
Charset charset)
给定字符串转为bytes后的byte数(byte长度)
|
static byte[] |
bytes(CharSequence str)
编码字符串
使用系统默认编码 |
static byte[] |
bytes(CharSequence str,
Charset charset)
编码字符串
|
static byte[] |
bytes(CharSequence str,
String charset)
编码字符串
|
static String |
center(CharSequence str,
int size)
居中字符串,两边补充指定字符串,如果指定长度小于字符串,则返回原字符串
CharSequenceUtil.center(null, *) = null
CharSequenceUtil.center("", 4) = " "
CharSequenceUtil.center("ab", -1) = "ab"
CharSequenceUtil.center("ab", 4) = " ab "
CharSequenceUtil.center("abcd", 2) = "abcd"
CharSequenceUtil.center("a", 4) = " a "
|
static String |
center(CharSequence str,
int size,
char padChar)
居中字符串,两边补充指定字符串,如果指定长度小于字符串,则返回原字符串
CharSequenceUtil.center(null, *, *) = null
CharSequenceUtil.center("", 4, ' ') = " "
CharSequenceUtil.center("ab", -1, ' ') = "ab"
CharSequenceUtil.center("ab", 4, ' ') = " ab "
CharSequenceUtil.center("abcd", 2, ' ') = "abcd"
CharSequenceUtil.center("a", 4, ' ') = " a "
CharSequenceUtil.center("a", 4, 'y') = "yayy"
CharSequenceUtil.center("abc", 7, ' ') = " abc "
|
static String |
center(CharSequence str,
int size,
CharSequence padStr)
居中字符串,两边补充指定字符串,如果指定长度小于字符串,则返回原字符串
CharSequenceUtil.center(null, *, *) = null
CharSequenceUtil.center("", 4, " ") = " "
CharSequenceUtil.center("ab", -1, " ") = "ab"
CharSequenceUtil.center("ab", 4, " ") = " ab "
CharSequenceUtil.center("abcd", 2, " ") = "abcd"
CharSequenceUtil.center("a", 4, " ") = " a "
CharSequenceUtil.center("a", 4, "yz") = "yayz"
CharSequenceUtil.center("abc", 7, null) = " abc "
CharSequenceUtil.center("abc", 7, "") = " abc "
|
static String |
cleanBlank(CharSequence str)
清理空白字符
|
static CharSequence |
commonPrefix(CharSequence str1,
CharSequence str2)
字符串1和字符串2的公共前缀
|
static CharSequence |
commonSuffix(CharSequence str1,
CharSequence str2)
字符串1和字符串2的公共后缀
|
static int |
compare(CharSequence str1,
CharSequence str2,
boolean nullIsLess)
比较两个字符串,用于排序
CharSequenceUtil.compare(null, null, *) = 0
CharSequenceUtil.compare(null , "a", true) < 0
CharSequenceUtil.compare(null , "a", false) > 0
CharSequenceUtil.compare("a", null, true) > 0
CharSequenceUtil.compare("a", null, false) < 0
CharSequenceUtil.compare("abc", "abc", *) = 0
CharSequenceUtil.compare("a", "b", *) < 0
CharSequenceUtil.compare("b", "a", *) > 0
CharSequenceUtil.compare("a", "B", *) > 0
CharSequenceUtil.compare("ab", "abc", *) < 0
|
static int |
compareIgnoreCase(CharSequence str1,
CharSequence str2,
boolean nullIsLess)
比较两个字符串,用于排序,大小写不敏感
CharSequenceUtil.compareIgnoreCase(null, null, *) = 0
CharSequenceUtil.compareIgnoreCase(null , "a", true) < 0
CharSequenceUtil.compareIgnoreCase(null , "a", false) > 0
CharSequenceUtil.compareIgnoreCase("a", null, true) > 0
CharSequenceUtil.compareIgnoreCase("a", null, false) < 0
CharSequenceUtil.compareIgnoreCase("abc", "abc", *) = 0
CharSequenceUtil.compareIgnoreCase("abc", "ABC", *) = 0
CharSequenceUtil.compareIgnoreCase("a", "b", *) < 0
CharSequenceUtil.compareIgnoreCase("b", "a", *) > 0
CharSequenceUtil.compareIgnoreCase("a", "B", *) < 0
CharSequenceUtil.compareIgnoreCase("A", "b", *) < 0
CharSequenceUtil.compareIgnoreCase("ab", "abc", *) < 0
|
static int |
compareVersion(CharSequence version1,
CharSequence version2)
比较两个版本
null版本排在最小:即: CharSequenceUtil.compareVersion(null, "v1") < 0 CharSequenceUtil.compareVersion("v1", "v1") = 0 CharSequenceUtil.compareVersion(null, null) = 0 CharSequenceUtil.compareVersion("v1", null) > 0 CharSequenceUtil.compareVersion("1.0.0", "1.0.2") < 0 CharSequenceUtil.compareVersion("1.0.2", "1.0.2a") < 0 CharSequenceUtil.compareVersion("1.13.0", "1.12.1c") > 0 CharSequenceUtil.compareVersion("V0.0.20170102", "V0.0.20170101") > 0 |
static String |
concat(boolean isNullToEmpty,
CharSequence... strs)
连接多个字符串为一个
|
static boolean |
contains(CharSequence str,
char searchChar)
指定字符是否在字符串中出现过
|
static boolean |
contains(CharSequence str,
CharSequence searchStr)
指定字符串是否在字符串中出现过
|
static boolean |
containsAll(CharSequence str,
CharSequence... testChars)
检查指定字符串中是否含给定的所有字符串
|
static boolean |
containsAny(CharSequence str,
char... testChars)
查找指定字符串是否包含指定字符列表中的任意一个字符
|
static boolean |
containsAny(CharSequence str,
CharSequence... testStrs)
查找指定字符串是否包含指定字符串列表中的任意一个字符串
|
static boolean |
containsAnyIgnoreCase(CharSequence str,
CharSequence... testStrs)
查找指定字符串是否包含指定字符串列表中的任意一个字符串
忽略大小写 |
static boolean |
containsBlank(CharSequence str)
给定字符串是否包含空白符(空白符包括空格、制表符、全角空格和不间断空格)
如果给定字符串为null或者"",则返回false |
static boolean |
containsIgnoreCase(CharSequence str,
CharSequence testStr)
是否包含特定字符,忽略大小写,如果给定两个参数都为
null ,返回true |
static boolean |
containsOnly(CharSequence str,
char... testChars)
检查指定字符串中是否只包含给定的字符
这里的containsOnly并不是必须全部给定的testChars都需要有,而是一个子集。 |
static int |
count(CharSequence content,
char charForSearch)
统计指定内容中包含指定字符的数量
|
static int |
count(CharSequence content,
CharSequence strForSearch)
统计指定内容中包含指定字符串的数量
参数为 null 或者 "" 返回 0 . |
static String[] |
cut(CharSequence str,
int partLength)
将字符串切分为N等份
|
static String |
desensitized(CharSequence str,
DesensitizedUtil.DesensitizedType desensitizedType)
脱敏,使用默认的脱敏策略
CharSequenceUtil.desensitized("100", DesensitizedUtil.DesensitizedType.USER_ID)) = "0"
CharSequenceUtil.desensitized("段正淳", DesensitizedUtil.DesensitizedType.CHINESE_NAME)) = "段**"
CharSequenceUtil.desensitized("51343620000320711X", DesensitizedUtil.DesensitizedType.ID_CARD)) = "5***************1X"
CharSequenceUtil.desensitized("09157518479", DesensitizedUtil.DesensitizedType.FIXED_PHONE)) = "0915*****79"
CharSequenceUtil.desensitized("18049531999", DesensitizedUtil.DesensitizedType.MOBILE_PHONE)) = "180****1999"
CharSequenceUtil.desensitized("北京市海淀区马连洼街道289号", DesensitizedUtil.DesensitizedType.ADDRESS)) = "北京市海淀区马********"
CharSequenceUtil.desensitized("duandazhi-jack@gmail.com.cn", DesensitizedUtil.DesensitizedType.EMAIL)) = "d*************@gmail.com.cn"
CharSequenceUtil.desensitized("1234567890", DesensitizedUtil.DesensitizedType.PASSWORD)) = "**********"
CharSequenceUtil.desensitized("苏D40000", DesensitizedUtil.DesensitizedType.CAR_LICENSE)) = "苏D4***0"
CharSequenceUtil.desensitized("11011111222233333256", DesensitizedType.BANK_CARD)) = "1101 **** **** **** 3256"
|
static String |
emptyIfNull(CharSequence str)
当给定字符串为null时,转换为Empty
|
static String |
emptyToDefault(CharSequence str,
String defaultStr)
如果字符串是
null 或者"",则返回指定默认字符串,否则返回字符串本身。 |
static String |
emptyToNull(CharSequence str)
当给定字符串为空字符串时,转换为
null |
static boolean |
endWith(CharSequence str,
char c)
字符串是否以给定字符结尾
|
static boolean |
endWith(CharSequence str,
CharSequence suffix)
是否以指定字符串结尾
|
static boolean |
endWith(CharSequence str,
CharSequence suffix,
boolean ignoreCase)
是否以指定字符串结尾
如果给定的字符串和开头字符串都为null则返回true,否则任意一个值为null返回false |
static boolean |
endWith(CharSequence str,
CharSequence suffix,
boolean ignoreCase,
boolean ignoreEquals)
是否以指定字符串结尾
如果给定的字符串和开头字符串都为null则返回true,否则任意一个值为null返回false |
static boolean |
endWithAny(CharSequence str,
CharSequence... suffixes)
给定字符串是否以任何一个字符串结尾
给定字符串和数组为空都返回false |
static boolean |
endWithAnyIgnoreCase(CharSequence str,
CharSequence... suffixes)
给定字符串是否以任何一个字符串结尾(忽略大小写)
给定字符串和数组为空都返回false |
static boolean |
endWithIgnoreCase(CharSequence str,
CharSequence suffix)
是否以指定字符串结尾,忽略大小写
|
static boolean |
equals(CharSequence str1,
CharSequence str2)
比较两个字符串(大小写敏感)。
|
static boolean |
equals(CharSequence str1,
CharSequence str2,
boolean ignoreCase)
比较两个字符串是否相等,规则如下
str1和str2都为
null
忽略大小写使用String.equalsIgnoreCase(String) 判断相等
不忽略大小写使用String.contentEquals(CharSequence) 判断相等
|
static boolean |
equalsAny(CharSequence str1,
boolean ignoreCase,
CharSequence... strs)
给定字符串是否与提供的中任一字符串相同,相同则返回
true ,没有相同的返回false 如果参与比对的字符串列表为空,返回 false |
static boolean |
equalsAny(CharSequence str1,
CharSequence... strs)
给定字符串是否与提供的中任一字符串相同,相同则返回
true ,没有相同的返回false 如果参与比对的字符串列表为空,返回 false |
static boolean |
equalsAnyIgnoreCase(CharSequence str1,
CharSequence... strs)
给定字符串是否与提供的中任一字符串相同(忽略大小写),相同则返回
true ,没有相同的返回false 如果参与比对的字符串列表为空,返回 false |
static boolean |
equalsCharAt(CharSequence str,
int position,
char c)
字符串指定位置的字符是否与给定字符相同
如果字符串为null,返回false 如果给定的位置大于字符串长度,返回false 如果给定的位置小于0,返回false |
static boolean |
equalsIgnoreCase(CharSequence str1,
CharSequence str2)
比较两个字符串(大小写不敏感)。
|
static String |
filter(CharSequence str,
Filter<Character> filter)
过滤字符串
|
static <T extends CharSequence> |
firstNonBlank(T... strs)
返回第一个非blank 元素
|
static <T extends CharSequence> |
firstNonEmpty(T... strs)
返回第一个非empty 元素
|
static <T extends CharSequence> |
firstNonNull(T... strs)
返回第一个非
null 元素 |
static String |
fixLength(CharSequence str,
char fixedChar,
int length)
在给定字符串末尾填充指定字符,以达到给定长度
如果字符串本身的长度大于等于length,返回原字符串 |
static String |
format(CharSequence template,
Object... params)
格式化文本, {} 表示占位符
此方法只是简单将占位符 {} 按照顺序替换为参数 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可 例: 通常使用:format("this is {} for {}", "a", "b") =》 this is a for b 转义{}: format("this is \\{} for {}", "a", "b") =》 this is {} for a 转义\: format("this is \\\\{} for {}", "a", "b") =》 this is \a for b |
static String |
genGetter(CharSequence fieldName)
生成get方法名
|
static String |
genSetter(CharSequence fieldName)
生成set方法名
例如:name 返回 setName |
static String |
getContainsStr(CharSequence str,
CharSequence... testStrs)
查找指定字符串是否包含指定字符串列表中的任意一个字符串,如果包含返回找到的第一个字符串
|
static String |
getContainsStrIgnoreCase(CharSequence str,
CharSequence... testStrs)
查找指定字符串是否包含指定字符串列表中的任意一个字符串,如果包含返回找到的第一个字符串
忽略大小写 |
static String |
getGeneralField(CharSequence getOrSetMethodName)
获得set或get或is方法对应的标准属性名
例如:setName 返回 name getName =》name setName =》name isName =》name |
static boolean |
hasBlank(CharSequence... strs)
指定字符串数组中,是否包含空字符串。
|
static boolean |
hasEmpty(CharSequence... strs)
是否包含空字符串。
|
static boolean |
hasLetter(CharSequence str)
指定字符串数组中,是否包含空字符串。
|
static String |
hide(CharSequence str,
int startInclude,
int endExclude)
替换指定字符串的指定区间内字符为"*"
俗称:脱敏功能,后面其他功能,可以见:DesensitizedUtil(脱敏工具类)
CharSequenceUtil.hide(null,*,*)=null
CharSequenceUtil.hide("",0,*)=""
CharSequenceUtil.hide("jackduan@163.com",-1,4) ****duan@163.com
CharSequenceUtil.hide("jackduan@163.com",2,3) ja*kduan@163.com
CharSequenceUtil.hide("jackduan@163.com",3,2) jackduan@163.com
CharSequenceUtil.hide("jackduan@163.com",16,16) jackduan@163.com
CharSequenceUtil.hide("jackduan@163.com",16,17) jackduan@163.com
|
static String |
indexedFormat(CharSequence pattern,
Object... arguments)
有序的格式化文本,使用{number}做为占位符
通常使用:format("this is {0} for {1}", "a", "b") =》 this is a for b |
static int |
indexOf(CharSequence str,
char searchChar)
指定范围内查找指定字符
|
static int |
indexOf(CharSequence str,
char searchChar,
int start)
指定范围内查找指定字符
|
static int |
indexOf(CharSequence text,
char searchChar,
int start,
int end)
指定范围内查找指定字符
|
static int |
indexOf(CharSequence text,
CharSequence searchStr,
int from,
boolean ignoreCase)
指定范围内查找字符串
|
static int |
indexOfIgnoreCase(CharSequence str,
CharSequence searchStr)
指定范围内查找字符串,忽略大小写
CharSequenceUtil.indexOfIgnoreCase(null, *, *) = -1 CharSequenceUtil.indexOfIgnoreCase(*, null, *) = -1 CharSequenceUtil.indexOfIgnoreCase("", "", 0) = 0 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "A", 0) = 0 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "B", 0) = 2 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "B", 3) = 5 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "B", 9) = -1 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "B", -1) = 2 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "", 2) = 2 CharSequenceUtil.indexOfIgnoreCase("abc", "", 9) = -1 |
static int |
indexOfIgnoreCase(CharSequence str,
CharSequence searchStr,
int fromIndex)
指定范围内查找字符串
CharSequenceUtil.indexOfIgnoreCase(null, *, *) = -1
CharSequenceUtil.indexOfIgnoreCase(*, null, *) = -1
CharSequenceUtil.indexOfIgnoreCase("", "", 0) = 0
CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "A", 0) = 0
CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "B", 0) = 2
CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1
CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "B", 3) = 5
CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "B", 9) = -1
CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "B", -1) = 2
CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "", 2) = 2
CharSequenceUtil.indexOfIgnoreCase("abc", "", 9) = -1
|
static boolean |
isAllBlank(CharSequence... strs)
指定字符串数组中的元素,是否全部为空字符串。
|
static boolean |
isAllCharMatch(CharSequence value,
Matcher<Character> matcher)
字符串的每一个字符是否都与定义的匹配器匹配
|
static boolean |
isAllEmpty(CharSequence... strs)
指定字符串数组中的元素,是否全部为空字符串。
|
static boolean |
isAllNotBlank(CharSequence... args)
是否存都不为
null 或空对象或空白符的对象,通过hasBlank(CharSequence...) |
static boolean |
isAllNotEmpty(CharSequence... args)
指定字符串数组中的元素,是否都不为空字符串。
|
static boolean |
isBlank(CharSequence str)
字符串是否为空白,空白的定义如下:
null
空字符串:""
空格、全角空格、制表符、换行符,等不可见字符
例:
CharSequenceUtil.isBlank(null) // true
CharSequenceUtil.isBlank("") // true
CharSequenceUtil.isBlank(" \t\n") // true
CharSequenceUtil.isBlank("abc") // false
注意:该方法与 isEmpty(CharSequence) 的区别是:
该方法会校验空白字符,且性能相对于 isEmpty(CharSequence) 略慢。 |
static boolean |
isBlankOrUndefined(CharSequence str)
检查字符串是否为null、空白串、“null”、“undefined”
|
static boolean |
isCharEquals(CharSequence str)
检查给定字符串的所有字符是否都一样
|
static boolean |
isEmpty(CharSequence str)
字符串是否为空,空的定义如下:
null
空字符串:""
例:
CharSequenceUtil.isEmpty(null) // true
CharSequenceUtil.isEmpty("") // true
CharSequenceUtil.isEmpty(" \t\n") // false
CharSequenceUtil.isEmpty("abc") // false
注意:该方法与 isBlank(CharSequence) 的区别是:该方法不校验空白字符。 |
static boolean |
isEmptyOrUndefined(CharSequence str)
检查字符串是否为null、“”、“null”、“undefined”
|
static boolean |
isLowerCase(CharSequence str)
给定字符串中的字母是否全部为小写,判断依据如下:
1.
|
static boolean |
isNotBlank(CharSequence str)
字符串是否为非空白,非空白的定义如下:
不为
null
不为空字符串:""
不为空格、全角空格、制表符、换行符,等不可见字符
例:
CharSequenceUtil.isNotBlank(null) // false
CharSequenceUtil.isNotBlank("") // false
CharSequenceUtil.isNotBlank(" \t\n") // false
CharSequenceUtil.isNotBlank("abc") // true
注意:该方法与 isNotEmpty(CharSequence) 的区别是:
该方法会校验空白字符,且性能相对于 isNotEmpty(CharSequence) 略慢。 |
static boolean |
isNotEmpty(CharSequence str)
字符串是否为非空白,非空白的定义如下:
不为
null
不为空字符串:""
例:
CharSequenceUtil.isNotEmpty(null) // false
CharSequenceUtil.isNotEmpty("") // false
CharSequenceUtil.isNotEmpty(" \t\n") // true
CharSequenceUtil.isNotEmpty("abc") // true
注意:该方法与 isNotBlank(CharSequence) 的区别是:该方法不校验空白字符。 |
static boolean |
isNullOrUndefined(CharSequence str)
检查字符串是否为null、“null”、“undefined”
|
static boolean |
isNumeric(CharSequence str)
检查字符串是否都为数字组成
|
static boolean |
isSubEquals(CharSequence str1,
int start1,
CharSequence str2,
boolean ignoreCase)
截取第一个字串的部分字符,与第二个字符串比较(长度一致),判断截取的子串是否相同
任意一个字符串为null返回false |
static boolean |
isSubEquals(CharSequence str1,
int start1,
CharSequence str2,
int start2,
int length,
boolean ignoreCase)
截取两个字符串的不同部分(长度一致),判断截取的子串是否相同
任意一个字符串为null返回false |
static boolean |
isSurround(CharSequence str,
char prefix,
char suffix)
给定字符串是否被字符包围
|
static boolean |
isSurround(CharSequence str,
CharSequence prefix,
CharSequence suffix)
给定字符串是否被字符包围
|
static boolean |
isUpperCase(CharSequence str)
给定字符串中的字母是否全部为大写,判断依据如下:
1.
|
static boolean |
isWrap(CharSequence str,
char wrapper)
指定字符串是否被同一字符包装(前后都有这些字符串)
|
static boolean |
isWrap(CharSequence str,
char prefixChar,
char suffixChar)
指定字符串是否被包装
|
static boolean |
isWrap(CharSequence str,
String wrapper)
指定字符串是否被同一字符包装(前后都有这些字符串)
|
static boolean |
isWrap(CharSequence str,
String prefix,
String suffix)
指定字符串是否被包装
|
static <T> String |
join(CharSequence conjunction,
Iterable<T> iterable)
以 conjunction 为分隔符将多个对象转换为字符串
|
static String |
join(CharSequence conjunction,
Object... objs)
以 conjunction 为分隔符将多个对象转换为字符串
|
static int |
lastIndexOf(CharSequence text,
CharSequence searchStr,
int from,
boolean ignoreCase)
指定范围内查找字符串
fromIndex 为搜索起始位置,从后往前计数 |
static int |
lastIndexOfIgnoreCase(CharSequence str,
CharSequence searchStr)
指定范围内查找字符串,忽略大小写
|
static int |
lastIndexOfIgnoreCase(CharSequence str,
CharSequence searchStr,
int fromIndex)
指定范围内查找字符串,忽略大小写
fromIndex 为搜索起始位置,从后往前计数 |
static int |
length(CharSequence cs)
获取字符串的长度,如果为null返回0
|
static String |
lowerFirst(CharSequence str)
小写首字母
例如:str = Name, return name |
static String |
maxLength(CharSequence string,
int length)
限制字符串长度,如果超过指定长度,截取指定长度并在末尾加"..."
|
static String |
move(CharSequence str,
int startInclude,
int endExclude,
int moveLength)
循环位移指定位置的字符串为指定距离
当moveLength大于0向右位移,小于0向左位移,0不位移 当moveLength大于字符串长度时采取循环位移策略,即位移到头后从头(尾)位移,例如长度为10,位移13则表示位移3 |
static String |
normalize(CharSequence str)
对字符串归一化处理,如 "Á" 可以使用 "u00C1"或 "u0041u0301"表示,实际测试中两个字符串并不equals
因此使用此方法归一为一种表示形式,默认按照W3C通常建议的,在NFC中交换文本。 |
static String |
nullToDefault(CharSequence str,
String defaultStr)
如果字符串是
null ,则返回指定默认字符串,否则返回字符串本身。 |
static String |
nullToEmpty(CharSequence str)
当给定字符串为null时,转换为Empty
|
static int |
ordinalIndexOf(CharSequence str,
CharSequence searchStr,
int ordinal)
返回字符串 searchStr 在字符串 str 中第 ordinal 次出现的位置。
|
static String |
padAfter(CharSequence str,
int length,
char padChar)
补充字符串以满足最小长度,如果提供的字符串大于指定长度,截断之
CharSequenceUtil.padAfter(null, *, *);//null
CharSequenceUtil.padAfter("1", 3, '0');//"100"
CharSequenceUtil.padAfter("123", 2, '0');//"23"
CharSequenceUtil.padAfter("123", -1, '0')//"" 空串
|
static String |
padAfter(CharSequence str,
int length,
CharSequence padStr)
补充字符串以满足最小长度
CharSequenceUtil.padAfter(null, *, *);//null
CharSequenceUtil.padAfter("1", 3, "ABC");//"1AB"
CharSequenceUtil.padAfter("123", 2, "ABC");//"23"
|
static String |
padPre(CharSequence str,
int length,
char padChar)
补充字符串以满足最小长度,如果提供的字符串大于指定长度,截断之
同:leftPad (org.apache.commons.lang3.leftPad)
CharSequenceUtil.padPre(null, *, *);//null
CharSequenceUtil.padPre("1", 3, '0');//"001"
CharSequenceUtil.padPre("123", 2, '0');//"12"
|
static String |
padPre(CharSequence str,
int length,
CharSequence padStr)
补充字符串以满足指定长度,如果提供的字符串大于指定长度,截断之
同:leftPad (org.apache.commons.lang3.leftPad)
CharSequenceUtil.padPre(null, *, *);//null
CharSequenceUtil.padPre("1", 3, "ABC");//"AB1"
CharSequenceUtil.padPre("123", 2, "ABC");//"12"
CharSequenceUtil.padPre("1039", -1, "0");//"103"
|
static String |
prependIfMissing(CharSequence str,
CharSequence prefix,
boolean ignoreCase,
CharSequence... prefixes)
如果给定字符串不是以给定的一个或多个字符串为开头,则在首部添加起始字符串
|
static String |
prependIfMissing(CharSequence str,
CharSequence prefix,
CharSequence... prefixes)
如果给定字符串不是以给定的一个或多个字符串为开头,则在首部添加起始字符串
不忽略大小写 |
static String |
prependIfMissingIgnoreCase(CharSequence str,
CharSequence prefix,
CharSequence... prefixes)
如果给定字符串不是以给定的一个或多个字符串为开头,则在首部添加起始字符串
忽略大小写 |
static String |
removeAll(CharSequence str,
char... chars)
去除字符串中指定的多个字符,如有多个则全部去除
|
static String |
removeAll(CharSequence str,
CharSequence strToRemove)
移除字符串中所有给定字符串
例:removeAll("aa-bb-cc-dd", "-") =》 aabbccdd |
static String |
removeAllLineBreaks(CharSequence str)
去除所有换行符,包括:
1.
|
static String |
removeAllPrefix(CharSequence str,
CharSequence prefix)
去掉指定所有前缀,如:
str=abcdef, prefix=ab => return cdef
str=ababcdef, prefix=ab => return cdef
str=ababcdef, prefix="" => return ababcdef
str=ababcdef, prefix=null => return ababcdef
|
static String |
removeAllSuffix(CharSequence str,
CharSequence suffix)
去掉指定所有后缀,如:
str=11abab, suffix=ab => return 11
str=11ab, suffix=ab => return 11
str=11ab, suffix="" => return 11ab
str=11ab, suffix=null => return 11ab
|
static String |
removeAny(CharSequence str,
CharSequence... strsToRemove)
移除字符串中所有给定字符串,当某个字符串出现多次,则全部移除
例:removeAny("aa-bb-cc-dd", "a", "b") =》 --cc-dd |
static String |
removePreAndLowerFirst(CharSequence str,
CharSequence prefix)
去掉首部指定长度的字符串并将剩余字符串首字母小写
例如:str=setName, prefix=set =》 return name |
static String |
removePreAndLowerFirst(CharSequence str,
int preLength)
去掉首部指定长度的字符串并将剩余字符串首字母小写
例如:str=setName, preLength=3 =》 return name |
static 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 |
repeat(char c,
int count)
重复某个字符
CharSequenceUtil.repeat('e', 0) = ""
CharSequenceUtil.repeat('e', 3) = "eee"
CharSequenceUtil.repeat('e', -2) = ""
|
static String |
repeat(CharSequence str,
int count)
重复某个字符串
|
static String |
repeatAndJoin(CharSequence str,
int count,
CharSequence delimiter)
重复某个字符串并通过分界符连接
CharSequenceUtil.repeatAndJoin("?"
|
static String |
repeatByLength(CharSequence str,
int padLen)
重复某个字符串到指定长度
|
static String |
replace(CharSequence str,
CharSequence searchStr,
CharSequence replacement)
替换字符串中的指定字符串
|
static String |
replace(CharSequence str,
CharSequence searchStr,
CharSequence replacement,
boolean ignoreCase)
替换字符串中的指定字符串
|
static String |
replace(CharSequence str,
int fromIndex,
CharSequence searchStr,
CharSequence replacement,
boolean ignoreCase)
替换字符串中的指定字符串
|
static String |
replace(CharSequence str,
int startInclude,
int endExclude,
char replacedChar)
Deprecated.
|
static String |
replace(CharSequence str,
int startInclude,
int endExclude,
CharSequence replacedStr)
Deprecated.
|
static String |
replace(CharSequence str,
Pattern pattern,
Func1<Matcher,String> replaceFun)
替换所有正则匹配的文本,并使用自定义函数决定如何替换
replaceFun可以通过 Matcher 提取出匹配到的内容的不同部分,然后经过重新处理、组装变成新的内容放回原位。 |
static String |
replace(CharSequence str,
String regex,
Func1<Matcher,String> replaceFun)
替换所有正则匹配的文本,并使用自定义函数决定如何替换
|
static String |
replaceByCodePoint(CharSequence str,
int startInclude,
int endExclude,
char replacedChar)
替换指定字符串的指定区间内字符为固定字符
此方法使用 CharSequence.codePoints() 完成拆分替换 |
static String |
replaceByCodePoint(CharSequence str,
int startInclude,
int endExclude,
CharSequence replacedStr)
替换指定字符串的指定区间内字符为指定字符串,字符串只重复一次
此方法使用 CharSequence.codePoints() 完成拆分替换 |
static String |
replaceChars(CharSequence str,
char[] chars,
CharSequence replacedStr)
替换字符字符数组中所有的字符为replacedStr
|
static String |
replaceChars(CharSequence str,
String chars,
CharSequence replacedStr)
替换字符字符数组中所有的字符为replacedStr
提供的chars为所有需要被替换的字符,例如:"\r\n",则"\r"和"\n"都会被替换,哪怕他们单独存在 |
static String |
replaceFirst(CharSequence str,
CharSequence searchStr,
CharSequence replacedStr)
替换字符串中第一个指定字符串
|
static String |
replaceFirst(CharSequence str,
CharSequence searchStr,
CharSequence replacedStr,
boolean ignoreCase)
替换字符串中第一个指定字符串
|
static String |
replaceIgnoreCase(CharSequence str,
CharSequence searchStr,
CharSequence replacement)
替换字符串中的指定字符串,忽略大小写
|
static String |
replaceLast(CharSequence str,
CharSequence searchStr,
CharSequence replacedStr)
替换字符串中最后一个指定字符串
|
static String |
replaceLast(CharSequence str,
CharSequence searchStr,
CharSequence replacedStr,
boolean ignoreCase)
替换字符串中最后一个指定字符串
|
static List<String> |
split(CharSequence str,
char separator)
切分字符串
a#b#c =》 [a,b,c] a##b#c =》 [a,"",b,c] |
static List<String> |
split(CharSequence str,
char separator,
boolean isTrim,
boolean ignoreEmpty)
切分字符串,不限制分片数量
|
static List<String> |
split(CharSequence str,
char separator,
int limit)
切分字符串,不去除切分后每个元素两边的空白符,不去除空白项
|
static List<String> |
split(CharSequence str,
char separator,
int limit,
boolean isTrim,
boolean ignoreEmpty)
切分字符串
|
static <R> List<R> |
split(CharSequence str,
char separator,
int limit,
boolean ignoreEmpty,
Function<String,R> mapping)
切分字符串
|
static List<String> |
split(CharSequence str,
CharSequence separator)
切分字符串,如果分隔符不存在则返回原字符串
|
static List<String> |
split(CharSequence str,
CharSequence separator,
boolean isTrim,
boolean ignoreEmpty)
切分字符串
|
static List<String> |
split(CharSequence str,
CharSequence separator,
int limit,
boolean isTrim,
boolean ignoreEmpty)
切分字符串
|
static String[] |
split(CharSequence str,
int len)
根据给定长度,将给定字符串截取为多个部分
|
static String[] |
splitToArray(CharSequence str,
char separator)
切分字符串
|
static String[] |
splitToArray(CharSequence text,
char separator,
int limit)
切分字符串
|
static String[] |
splitToArray(CharSequence str,
CharSequence separator)
切分字符串,如果分隔符不存在则返回原字符串
|
static int[] |
splitToInt(CharSequence str,
char separator)
切分字符串为int数组
|
static int[] |
splitToInt(CharSequence str,
CharSequence separator)
切分字符串为int数组
|
static long[] |
splitToLong(CharSequence str,
char separator)
切分字符串为long数组
|
static long[] |
splitToLong(CharSequence str,
CharSequence separator)
切分字符串为long数组
|
static List<String> |
splitTrim(CharSequence str,
char separator)
切分字符串,去除切分后每个元素两边的空白符,去除空白项
|
static List<String> |
splitTrim(CharSequence str,
char separator,
int limit)
切分字符串,去除切分后每个元素两边的空白符,去除空白项
|
static List<String> |
splitTrim(CharSequence str,
CharSequence separator)
切分字符串,去除切分后每个元素两边的空白符,去除空白项
|
static List<String> |
splitTrim(CharSequence str,
CharSequence separator,
int limit)
切分字符串,去除切分后每个元素两边的空白符,去除空白项
|
static boolean |
startWith(CharSequence str,
char c)
字符串是否以给定字符开始
|
static boolean |
startWith(CharSequence str,
CharSequence prefix)
是否以指定字符串开头
|
static boolean |
startWith(CharSequence str,
CharSequence prefix,
boolean ignoreCase)
是否以指定字符串开头
如果给定的字符串和开头字符串都为null则返回true,否则任意一个值为null返回false |
static boolean |
startWith(CharSequence str,
CharSequence prefix,
boolean ignoreCase,
boolean ignoreEquals)
是否以指定字符串开头
如果给定的字符串和开头字符串都为null则返回true,否则任意一个值为null返回false CharSequenceUtil.startWith("123", "123", false, true); -- false CharSequenceUtil.startWith("ABCDEF", "abc", true, true); -- true CharSequenceUtil.startWith("abc", "abc", true, true); -- false |
static boolean |
startWithAny(CharSequence str,
CharSequence... prefixes)
给定字符串是否以任何一个字符串开始
给定字符串和数组为空都返回false |
static boolean |
startWithAnyIgnoreCase(CharSequence str,
CharSequence... prefixes)
给定字符串是否以任何一个字符串开始(忽略大小写)
给定字符串和数组为空都返回false |
static boolean |
startWithIgnoreCase(CharSequence str,
CharSequence prefix)
是否以指定字符串开头,忽略大小写
|
static boolean |
startWithIgnoreEquals(CharSequence str,
CharSequence prefix)
是否以指定字符串开头,忽略相等字符串的情况
|
static String |
str(CharSequence cs)
CharSequence 转为字符串,null安全 |
static StrBuilder |
strBuilder(CharSequence... strs)
创建StrBuilder对象
|
static String |
strip(CharSequence str,
CharSequence prefixOrSuffix)
去除两边的指定字符串
|
static String |
strip(CharSequence str,
CharSequence prefix,
CharSequence suffix)
去除两边的指定字符串
两边字符如果存在,则去除,不存在不做处理
"aaa_STRIPPED_bbb", "a", "b" -> "aa_STRIPPED_bb"
"aaa_STRIPPED_bbb", null, null -> "aaa_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "", "" -> "aaa_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "", "b" -> "aaa_STRIPPED_bb"
"aaa_STRIPPED_bbb", null, "b" -> "aaa_STRIPPED_bb"
"aaa_STRIPPED_bbb", "a", "" -> "aa_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "a", null -> "aa_STRIPPED_bbb"
"a", "a", "a" -> ""
|
static String |
strip(CharSequence str,
CharSequence prefix,
CharSequence suffix,
boolean ignoreCase)
去除两边的指定字符串
两边字符如果存在,则去除,不存在不做处理
"aaa_STRIPPED_bbb", "a", "b" -> "aa_STRIPPED_bb"
"aaa_STRIPPED_bbb", null, null -> "aaa_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "", "" -> "aaa_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "", "b" -> "aaa_STRIPPED_bb"
"aaa_STRIPPED_bbb", null, "b" -> "aaa_STRIPPED_bb"
"aaa_STRIPPED_bbb", "a", "" -> "aa_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "a", null -> "aa_STRIPPED_bbb"
"a", "a", "a" -> ""
|
static String |
stripAll(CharSequence str,
CharSequence prefixOrSuffix)
去除两边所有的指定字符串
"aaa_STRIPPED_bbb", "a" -> "_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "a", "b" -> "_STRIPPED_"
"aaa_STRIPPED_bbb", "" -> "aaa_STRIPPED_bbb"
|
static String |
stripAll(CharSequence str,
CharSequence prefix,
CharSequence suffix)
去除两边所有的指定字符串
"aaa_STRIPPED_bbb", "a", "b" -> "_STRIPPED_"
"aaa_STRIPPED_bbb", null, null -> "aaa_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "", "" -> "aaa_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "", "b" -> "aaa_STRIPPED_"
"aaa_STRIPPED_bbb", null, "b" -> "aaa_STRIPPED_"
"aaa_STRIPPED_bbb", "a", "" -> "_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "a", null -> "_STRIPPED_bbb"
// special test
"aaaaaabbb", "aaa", null -> "bbb"
"aaaaaaabbb", "aa", null -> "abbb"
"aaaaaaaaa", "aaa", "aa" -> ""
"a", "a", "a" -> ""
|
static String |
stripIgnoreCase(CharSequence str,
CharSequence prefixOrSuffix)
去除两边的指定字符串,忽略大小写
|
static String |
stripIgnoreCase(CharSequence str,
CharSequence prefix,
CharSequence suffix)
去除两边的指定字符串,忽略大小写
|
static String |
sub(CharSequence str,
int fromIndexInclude,
int toIndexExclude)
改进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 |
static String |
subAfter(CharSequence string,
char separator,
boolean isLastSeparator)
截取分隔字符串之后的字符串,不包括分隔字符串
如果给定的字符串为空串(null或""),返回原字符串 如果分隔字符串为空串(null或""),则返回空串,如果分隔字符串未找到,返回空串,举例如下: CharSequenceUtil.subAfter(null, *, false) = null CharSequenceUtil.subAfter("", *, false) = "" CharSequenceUtil.subAfter("abc", 'a', false) = "bc" CharSequenceUtil.subAfter("abcba", 'b', false) = "cba" CharSequenceUtil.subAfter("abc", 'c', false) = "" CharSequenceUtil.subAfter("abc", 'd', false) = "" |
static String |
subAfter(CharSequence string,
CharSequence separator,
boolean isLastSeparator)
截取分隔字符串之后的字符串,不包括分隔字符串
如果给定的字符串为空串(null或""),返回原字符串 如果分隔字符串为空串(null或""),则返回空串,如果分隔字符串未找到,返回空串,举例如下: CharSequenceUtil.subAfter(null, *, false) = null CharSequenceUtil.subAfter("", *, false) = "" CharSequenceUtil.subAfter(*, null, false) = "" CharSequenceUtil.subAfter("abc", "a", false) = "bc" CharSequenceUtil.subAfter("abcba", "b", false) = "cba" CharSequenceUtil.subAfter("abc", "c", false) = "" CharSequenceUtil.subAfter("abc", "d", false) = "" CharSequenceUtil.subAfter("abc", "", false) = "abc" |
static String |
subBefore(CharSequence string,
char separator,
boolean isLastSeparator)
截取分隔字符串之前的字符串,不包括分隔字符串
如果给定的字符串为空串(null或"")或者分隔字符串为null,返回原字符串 如果分隔字符串未找到,返回原字符串,举例如下: CharSequenceUtil.subBefore(null, *, false) = null CharSequenceUtil.subBefore("", *, false) = "" CharSequenceUtil.subBefore("abc", 'a', false) = "" CharSequenceUtil.subBefore("abcba", 'b', false) = "a" CharSequenceUtil.subBefore("abc", 'c', false) = "ab" CharSequenceUtil.subBefore("abc", 'd', false) = "abc" |
static String |
subBefore(CharSequence string,
CharSequence separator,
boolean isLastSeparator)
截取分隔字符串之前的字符串,不包括分隔字符串
如果给定的字符串为空串(null或"")或者分隔字符串为null,返回原字符串 如果分隔字符串为空串"",则返回空串,如果分隔字符串未找到,返回原字符串,举例如下: CharSequenceUtil.subBefore(null, *, false) = null CharSequenceUtil.subBefore("", *, false) = "" CharSequenceUtil.subBefore("abc", "a", false) = "" CharSequenceUtil.subBefore("abcba", "b", false) = "a" CharSequenceUtil.subBefore("abc", "c", false) = "ab" CharSequenceUtil.subBefore("abc", "d", false) = "abc" CharSequenceUtil.subBefore("abc", "", false) = "" CharSequenceUtil.subBefore("abc", null, false) = "abc" |
static String |
subBetween(CharSequence str,
CharSequence beforeAndAfter)
截取指定字符串中间部分,不包括标识字符串
栗子: CharSequenceUtil.subBetween(null, *) = null CharSequenceUtil.subBetween("", "") = "" CharSequenceUtil.subBetween("", "tag") = null CharSequenceUtil.subBetween("tagabctag", null) = null CharSequenceUtil.subBetween("tagabctag", "") = "" CharSequenceUtil.subBetween("tagabctag", "tag") = "abc" |
static String |
subBetween(CharSequence str,
CharSequence before,
CharSequence after)
截取指定字符串中间部分,不包括标识字符串
栗子: CharSequenceUtil.subBetween("wx[b]yz", "[", "]") = "b" CharSequenceUtil.subBetween(null, *, *) = null CharSequenceUtil.subBetween(*, null, *) = null CharSequenceUtil.subBetween(*, *, null) = null CharSequenceUtil.subBetween("", "", "") = "" CharSequenceUtil.subBetween("", "", "]") = null CharSequenceUtil.subBetween("", "[", "]") = null CharSequenceUtil.subBetween("yabcz", "", "") = "" CharSequenceUtil.subBetween("yabcz", "y", "z") = "abc" CharSequenceUtil.subBetween("yabczyabcz", "y", "z") = "abc" |
static String[] |
subBetweenAll(CharSequence str,
CharSequence prefixAndSuffix)
截取指定字符串多段中间部分,不包括标识字符串
栗子: CharSequenceUtil.subBetweenAll(null, *) = [] CharSequenceUtil.subBetweenAll(*, null) = [] CharSequenceUtil.subBetweenAll(*, *) = [] CharSequenceUtil.subBetweenAll("", "") = [] CharSequenceUtil.subBetweenAll("", "#") = [] CharSequenceUtil.subBetweenAll("gotanks", "") = [] CharSequenceUtil.subBetweenAll("#gotanks#", "#") = ["gotanks"] CharSequenceUtil.subBetweenAll("#hello# #world#!" |
static String[] |
subBetweenAll(CharSequence str,
CharSequence prefix,
CharSequence suffix)
截取指定字符串多段中间部分,不包括标识字符串
栗子: CharSequenceUtil.subBetweenAll("wx[b]y[z]", "[", "]") = ["b","z"] CharSequenceUtil.subBetweenAll(null, *, *) = [] CharSequenceUtil.subBetweenAll(*, null, *) = [] CharSequenceUtil.subBetweenAll(*, *, null) = [] CharSequenceUtil.subBetweenAll("", "", "") = [] CharSequenceUtil.subBetweenAll("", "", "]") = [] CharSequenceUtil.subBetweenAll("", "[", "]") = [] CharSequenceUtil.subBetweenAll("yabcz", "", "") = [] CharSequenceUtil.subBetweenAll("yabcz", "y", "z") = ["abc"] CharSequenceUtil.subBetweenAll("yabczyabcz", "y", "z") = ["abc","abc"] CharSequenceUtil.subBetweenAll("[yabc[zy]abcz]", "[", "]"); = ["zy"] 重叠时只截取内部, |
static String |
subByCodePoint(CharSequence str,
int fromIndex,
int toIndex)
通过CodePoint截取字符串,可以截断Emoji
|
static String |
subPre(CharSequence string,
int toIndexExclude)
切割指定位置之前部分的字符串
|
static String |
subPreGbk(CharSequence str,
int len,
boolean halfUp)
截取部分字符串,这里一个汉字的长度认为是2
可以自定义halfUp,如len为10,如果截取后最后一个字符是半个字符, true 表示保留,则长度是11,否则长度9 |
static String |
subPreGbk(CharSequence str,
int len,
CharSequence suffix)
截取部分字符串,这里一个汉字的长度认为是2
|
static String |
subSuf(CharSequence string,
int fromIndex)
切割指定位置之后部分的字符串
|
static String |
subSufByLength(CharSequence string,
int length)
切割指定长度的后部分的字符串
CharSequenceUtil.subSufByLength("abcde", 3) = "cde"
CharSequenceUtil.subSufByLength("abcde", 0) = ""
CharSequenceUtil.subSufByLength("abcde", -5) = ""
CharSequenceUtil.subSufByLength("abcde", -1) = ""
CharSequenceUtil.subSufByLength("abcde", 5) = "abcde"
CharSequenceUtil.subSufByLength("abcde", 10) = "abcde"
CharSequenceUtil.subSufByLength(null, 3) = null
|
static String |
subWithLength(String input,
int fromIndex,
int length)
截取字符串,从指定位置开始,截取指定长度的字符串
如果fromIndex为正数,则向后截取指定length长度,如果为负数,则向前截取length长度。 |
static String |
swapCase(String str)
切换给定字符串中的大小写。
|
static String |
toCamelCase(CharSequence name)
将下划线方式命名的字符串转换为驼峰式。
|
static String |
toCamelCase(CharSequence name,
char symbol)
将连接符方式命名的字符串转换为驼峰式。
|
static String |
toSymbolCase(CharSequence str,
char symbol)
将驼峰式命名的字符串转换为使用符号连接方式。
|
static int |
totalLength(CharSequence... strs)
给定字符串数组的总长度
null字符长度定义为0 |
static String |
toUnderlineCase(CharSequence str)
将驼峰式命名的字符串转换为下划线方式。
|
static String |
trim(CharSequence str)
除去字符串头尾部的空白,如果字符串是
null ,依然返回null 。 |
static String |
trim(CharSequence str,
int mode)
除去字符串头尾部的空白符,如果字符串是
null ,依然返回null 。 |
static String |
trim(CharSequence str,
int mode,
Predicate<Character> predicate)
按照断言,除去字符串头尾部的断言为真的字符,如果字符串是
null ,依然返回null 。 |
static String |
trimEnd(CharSequence str)
除去字符串尾部的空白,如果字符串是
null ,则返回null 。 |
static String |
trimStart(CharSequence str)
除去字符串头部的空白,如果字符串是
null ,则返回null 。 |
static String |
trimToEmpty(CharSequence str)
除去字符串头尾部的空白,如果字符串是
null ,返回"" 。 |
static String |
trimToNull(CharSequence str)
除去字符串头尾部的空白,如果字符串是
null 或者"",返回null 。 |
static String |
unWrap(CharSequence str,
char prefixAndSuffix)
去掉字符包装,如果未被包装则返回原字符串
|
static String |
unWrap(CharSequence str,
char prefix,
char suffix)
去掉字符包装,如果未被包装则返回原字符串
|
static String |
unWrap(CharSequence str,
String prefix,
String suffix)
去掉字符包装,如果未被包装则返回原字符串
|
static String |
upperFirst(CharSequence str)
大写首字母
例如:str = name, return Name |
static String |
upperFirstAndAddPre(CharSequence str,
String preString)
原字符串首字母大写并在其首部添加指定字符串 例如:str=name, preString=get =》 return getName
|
static byte[] |
utf8Bytes(CharSequence str)
编码字符串,编码为UTF-8
|
static String |
wrap(CharSequence str,
CharSequence prefixAndSuffix)
包装指定字符串
当前缀和后缀一致时使用此方法 |
static String |
wrap(CharSequence str,
CharSequence prefix,
CharSequence suffix)
包装指定字符串
|
static String[] |
wrapAll(CharSequence prefix,
CharSequence suffix,
CharSequence... strs)
包装多个字符串
|
static String[] |
wrapAllIfMissing(CharSequence prefix,
CharSequence suffix,
CharSequence... strs)
包装多个字符串,如果已经包装,则不再包装
|
static String[] |
wrapAllWithPair(CharSequence prefixAndSuffix,
CharSequence... strs)
使用单个字符包装多个字符串
|
static String[] |
wrapAllWithPairIfMissing(CharSequence prefixAndSuffix,
CharSequence... strs)
使用成对的字符包装多个字符串,如果已经包装,则不再包装
|
static String |
wrapIfMissing(CharSequence str,
CharSequence prefix,
CharSequence suffix)
包装指定字符串,如果前缀或后缀已经包含对应的字符串,则不再包装
|
public static final int INDEX_NOT_FOUND
public static final String NULL
"null"
"null" != null
public static final String EMPTY
""
public static final String SPACE
" "
public static boolean isBlank(CharSequence str)
字符串是否为空白,空白的定义如下:
null
""
例:
CharSequenceUtil.isBlank(null) // true
CharSequenceUtil.isBlank("") // true
CharSequenceUtil.isBlank(" \t\n") // true
CharSequenceUtil.isBlank("abc") // false
注意:该方法与 isEmpty(CharSequence)
的区别是:
该方法会校验空白字符,且性能相对于 isEmpty(CharSequence)
略慢。
建议:
hasBlank(CharSequence...)
或 isAllBlank(CharSequence...)
str
- 被检测的字符串isEmpty(CharSequence)
public static boolean isNotBlank(CharSequence str)
字符串是否为非空白,非空白的定义如下:
null
""
例:
CharSequenceUtil.isNotBlank(null) // false
CharSequenceUtil.isNotBlank("") // false
CharSequenceUtil.isNotBlank(" \t\n") // false
CharSequenceUtil.isNotBlank("abc") // true
注意:该方法与 isNotEmpty(CharSequence)
的区别是:
该方法会校验空白字符,且性能相对于 isNotEmpty(CharSequence)
略慢。
建议:仅对于客户端(或第三方接口)传入的参数使用该方法。
str
- 被检测的字符串isBlank(CharSequence)
public static boolean hasBlank(CharSequence... strs)
指定字符串数组中,是否包含空字符串。
如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true。
例:
CharSequenceUtil.hasBlank() // true
CharSequenceUtil.hasBlank("", null, " ") // true
CharSequenceUtil.hasBlank("123", " ") // true
CharSequenceUtil.hasBlank("123", "abc") // false
注意:该方法与 isAllBlank(CharSequence...)
的区别在于:
isBlank(...) || isBlank(...) || ...
isAllBlank(CharSequence...)
等价于 isBlank(...) && isBlank(...) && ...
strs
- 字符串列表public static boolean isAllBlank(CharSequence... strs)
指定字符串数组中的元素,是否全部为空字符串。
如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true。
例:
CharSequenceUtil.isAllBlank() // true
CharSequenceUtil.isAllBlank("", null, " ") // true
CharSequenceUtil.isAllBlank("123", " ") // false
CharSequenceUtil.isAllBlank("123", "abc") // false
注意:该方法与 hasBlank(CharSequence...)
的区别在于:
hasBlank(CharSequence...)
等价于 isBlank(...) || isBlank(...) || ...
isBlank(...) && isBlank(...) && ...
strs
- 字符串列表public static boolean isEmpty(CharSequence str)
字符串是否为空,空的定义如下:
null
""
例:
CharSequenceUtil.isEmpty(null) // true
CharSequenceUtil.isEmpty("") // true
CharSequenceUtil.isEmpty(" \t\n") // false
CharSequenceUtil.isEmpty("abc") // false
注意:该方法与 isBlank(CharSequence)
的区别是:该方法不校验空白字符。
建议:
hasEmpty(CharSequence...)
或 isAllEmpty(CharSequence...)
str
- 被检测的字符串isBlank(CharSequence)
public static boolean isNotEmpty(CharSequence str)
字符串是否为非空白,非空白的定义如下:
null
""
例:
CharSequenceUtil.isNotEmpty(null) // false
CharSequenceUtil.isNotEmpty("") // false
CharSequenceUtil.isNotEmpty(" \t\n") // true
CharSequenceUtil.isNotEmpty("abc") // true
注意:该方法与 isNotBlank(CharSequence)
的区别是:该方法不校验空白字符。
建议:该方法建议用于工具类或任何可以预期的方法参数的校验中。
str
- 被检测的字符串isEmpty(CharSequence)
public static String emptyIfNull(CharSequence str)
str
- 被检查的字符串nullToEmpty(CharSequence)
public static String nullToEmpty(CharSequence str)
str
- 被转换的字符串public static String nullToDefault(CharSequence str, String defaultStr)
null
,则返回指定默认字符串,否则返回字符串本身。
nullToDefault(null, "default") = "default" nullToDefault("", "default") = "" nullToDefault(" ", "default") = " " nullToDefault("bat", "default") = "bat"
str
- 要转换的字符串defaultStr
- 默认字符串public static String emptyToDefault(CharSequence str, String defaultStr)
null
或者"",则返回指定默认字符串,否则返回字符串本身。
emptyToDefault(null, "default") = "default" emptyToDefault("", "default") = "default" emptyToDefault(" ", "default") = " " emptyToDefault("bat", "default") = "bat"
str
- 要转换的字符串defaultStr
- 默认字符串public static String blankToDefault(CharSequence str, String defaultStr)
null
或者""或者空白,则返回指定默认字符串,否则返回字符串本身。
blankToDefault(null, "default") = "default" blankToDefault("", "default") = "default" blankToDefault(" ", "default") = "default" blankToDefault("bat", "default") = "bat"
str
- 要转换的字符串defaultStr
- 默认字符串public static String emptyToNull(CharSequence str)
null
str
- 被转换的字符串public static boolean hasEmpty(CharSequence... strs)
是否包含空字符串。
如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true。
例:
CharSequenceUtil.hasEmpty() // true
CharSequenceUtil.hasEmpty("", null) // true
CharSequenceUtil.hasEmpty("123", "") // true
CharSequenceUtil.hasEmpty("123", "abc") // false
CharSequenceUtil.hasEmpty(" ", "\t", "\n") // false
注意:该方法与 isAllEmpty(CharSequence...)
的区别在于:
isEmpty(...) || isEmpty(...) || ...
isAllEmpty(CharSequence...)
等价于 isEmpty(...) && isEmpty(...) && ...
strs
- 字符串列表public static boolean isAllEmpty(CharSequence... strs)
指定字符串数组中的元素,是否全部为空字符串。
如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true。
例:
CharSequenceUtil.isAllEmpty() // true
CharSequenceUtil.isAllEmpty("", null) // true
CharSequenceUtil.isAllEmpty("123", "") // false
CharSequenceUtil.isAllEmpty("123", "abc") // false
CharSequenceUtil.isAllEmpty(" ", "\t", "\n") // false
注意:该方法与 hasEmpty(CharSequence...)
的区别在于:
hasEmpty(CharSequence...)
等价于 isEmpty(...) || isEmpty(...) || ...
isEmpty(...) && isEmpty(...) && ...
strs
- 字符串列表public static boolean isAllNotEmpty(CharSequence... args)
指定字符串数组中的元素,是否都不为空字符串。
如果指定的字符串数组的长度不为 0,或者所有元素都不是空字符串,则返回 true。
例:
CharSequenceUtil.isAllNotEmpty() // false
CharSequenceUtil.isAllNotEmpty("", null) // false
CharSequenceUtil.isAllNotEmpty("123", "") // false
CharSequenceUtil.isAllNotEmpty("123", "abc") // true
CharSequenceUtil.isAllNotEmpty(" ", "\t", "\n") // true
注意:该方法与 isAllEmpty(CharSequence...)
的区别在于:
isAllEmpty(CharSequence...)
等价于 isEmpty(...) && isEmpty(...) && ...
!isEmpty(...) && !isEmpty(...) && ...
args
- 字符串数组public static boolean isAllNotBlank(CharSequence... args)
null
或空对象或空白符的对象,通过hasBlank(CharSequence...)
判断元素args
- 被检查的对象,一个或者多个public static boolean isNullOrUndefined(CharSequence str)
str
- 被检查的字符串public static boolean isEmptyOrUndefined(CharSequence str)
str
- 被检查的字符串public static boolean isBlankOrUndefined(CharSequence str)
str
- 被检查的字符串public static String trim(CharSequence str)
null
,依然返回null
。
注意,和String.trim()
不同,此方法使用CharUtil.isBlankChar(char)
来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
trim(null) = null trim("") = "" trim(" ") = "" trim("abc") = "abc" trim(" abc ") = "abc"
str
- 要处理的字符串null
,则返回null
public static String trimToEmpty(CharSequence str)
null
,返回""
。
CharSequenceUtil.trimToEmpty(null) = "" CharSequenceUtil.trimToEmpty("") = "" CharSequenceUtil.trimToEmpty(" ") = "" CharSequenceUtil.trimToEmpty("abc") = "abc" CharSequenceUtil.trimToEmpty(" abc ") = "abc"
str
- 字符串public static String trimToNull(CharSequence str)
null
或者"",返回null
。
CharSequenceUtil.trimToNull(null) = null CharSequenceUtil.trimToNull("") = null CharSequenceUtil.trimToNull(" ") = null CharSequenceUtil.trimToNull("abc") = "abc" CharSequenceUtil.trimToEmpty(" abc ") = "abc"
str
- 字符串public static String trimStart(CharSequence str)
null
,则返回null
。
注意,和String.trim()
不同,此方法使用CharUtil.isBlankChar(char)
来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
trimStart(null) = null trimStart("") = "" trimStart("abc") = "abc" trimStart(" abc") = "abc" trimStart("abc ") = "abc " trimStart(" abc ") = "abc "
str
- 要处理的字符串null
或结果字符串为""
,则返回 null
public static String trimEnd(CharSequence str)
null
,则返回null
。
注意,和String.trim()
不同,此方法使用CharUtil.isBlankChar(char)
来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
trimEnd(null) = null trimEnd("") = "" trimEnd("abc") = "abc" trimEnd(" abc") = " abc" trimEnd("abc ") = "abc" trimEnd(" abc ") = " abc"
str
- 要处理的字符串null
或结果字符串为""
,则返回 null
public static String trim(CharSequence str, int mode)
null
,依然返回null
。str
- 要处理的字符串mode
- -1
表示trimStart,0
表示trim全部, 1
表示trimEndnull
,则返回null
public static String trim(CharSequence str, int mode, Predicate<Character> predicate)
null
,依然返回null
。str
- 要处理的字符串mode
- -1
表示trimStart,0
表示trim全部, 1
表示trimEndpredicate
- 断言是否过掉字符,返回true
表述过滤掉,false
表示不过滤null
,则返回null
public static boolean startWith(CharSequence str, char c)
str
- 字符串c
- 字符public static boolean startWith(CharSequence str, CharSequence prefix, boolean ignoreCase)
str
- 被监测字符串prefix
- 开头字符串ignoreCase
- 是否忽略大小写public static boolean startWith(CharSequence str, CharSequence prefix, boolean ignoreCase, boolean ignoreEquals)
CharSequenceUtil.startWith("123", "123", false, true); -- false CharSequenceUtil.startWith("ABCDEF", "abc", true, true); -- true CharSequenceUtil.startWith("abc", "abc", true, true); -- false
str
- 被监测字符串prefix
- 开头字符串ignoreCase
- 是否忽略大小写ignoreEquals
- 是否忽略字符串相等的情况public static boolean startWith(CharSequence str, CharSequence prefix)
str
- 被监测字符串prefix
- 开头字符串public static boolean startWithIgnoreEquals(CharSequence str, CharSequence prefix)
str
- 被监测字符串prefix
- 开头字符串public static boolean startWithIgnoreCase(CharSequence str, CharSequence prefix)
str
- 被监测字符串prefix
- 开头字符串public static boolean startWithAny(CharSequence str, CharSequence... prefixes)
str
- 给定字符串prefixes
- 需要检测的开始字符串public static boolean startWithAnyIgnoreCase(CharSequence str, CharSequence... prefixes)
str
- 给定字符串prefixes
- 需要检测的开始字符串public static boolean endWith(CharSequence str, char c)
str
- 字符串c
- 字符public static boolean endWith(CharSequence str, CharSequence suffix, boolean ignoreCase)
str
- 被监测字符串suffix
- 结尾字符串ignoreCase
- 是否忽略大小写public static boolean endWith(CharSequence str, CharSequence suffix, boolean ignoreCase, boolean ignoreEquals)
str
- 被监测字符串suffix
- 结尾字符串ignoreCase
- 是否忽略大小写ignoreEquals
- 是否忽略字符串相等的情况public static boolean endWith(CharSequence str, CharSequence suffix)
str
- 被监测字符串suffix
- 结尾字符串public static boolean endWithIgnoreCase(CharSequence str, CharSequence suffix)
str
- 被监测字符串suffix
- 结尾字符串public static boolean endWithAny(CharSequence str, CharSequence... suffixes)
str
- 给定字符串suffixes
- 需要检测的结尾字符串public static boolean endWithAnyIgnoreCase(CharSequence str, CharSequence... suffixes)
str
- 给定字符串suffixes
- 需要检测的结尾字符串public static boolean contains(CharSequence str, char searchChar)
str
- 字符串searchChar
- 被查找的字符public static boolean contains(CharSequence str, CharSequence searchStr)
str
- 字符串searchStr
- 被查找的字符串public static boolean containsAny(CharSequence str, CharSequence... testStrs)
str
- 指定字符串testStrs
- 需要检查的字符串数组public static boolean containsAny(CharSequence str, char... testChars)
str
- 指定字符串testChars
- 需要检查的字符数组public static boolean containsOnly(CharSequence str, char... testChars)
StrUtil.containsOnly("asdas", 'a', 'd', 's','l'); --> true
str
- 字符串testChars
- 检查的字符public static boolean containsAll(CharSequence str, CharSequence... testChars)
str
- 字符串testChars
- 检查的字符public static boolean containsBlank(CharSequence str)
str
- 字符串public static String getContainsStr(CharSequence str, CharSequence... testStrs)
str
- 指定字符串testStrs
- 需要检查的字符串数组public static boolean containsIgnoreCase(CharSequence str, CharSequence testStr)
null
,返回truestr
- 被检测字符串testStr
- 被测试是否包含的字符串public static boolean containsAnyIgnoreCase(CharSequence str, CharSequence... testStrs)
str
- 指定字符串testStrs
- 需要检查的字符串数组public static String getContainsStrIgnoreCase(CharSequence str, CharSequence... testStrs)
str
- 指定字符串testStrs
- 需要检查的字符串数组public static int indexOf(CharSequence str, char searchChar)
str
- 字符串searchChar
- 被查找的字符public static int indexOf(CharSequence str, char searchChar, int start)
str
- 字符串searchChar
- 被查找的字符start
- 起始位置,如果小于0,从0开始查找public static int indexOf(CharSequence text, char searchChar, int start, int end)
text
- 字符串searchChar
- 被查找的字符start
- 起始位置,如果小于0,从0开始查找end
- 终止位置,如果超过str.length()则默认查找到字符串末尾public static int indexOfIgnoreCase(CharSequence str, CharSequence searchStr)
CharSequenceUtil.indexOfIgnoreCase(null, *, *) = -1 CharSequenceUtil.indexOfIgnoreCase(*, null, *) = -1 CharSequenceUtil.indexOfIgnoreCase("", "", 0) = 0 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "A", 0) = 0 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "B", 0) = 2 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "B", 3) = 5 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "B", 9) = -1 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "B", -1) = 2 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "", 2) = 2 CharSequenceUtil.indexOfIgnoreCase("abc", "", 9) = -1
str
- 字符串searchStr
- 需要查找位置的字符串public static int indexOfIgnoreCase(CharSequence str, CharSequence searchStr, int fromIndex)
CharSequenceUtil.indexOfIgnoreCase(null, *, *) = -1 CharSequenceUtil.indexOfIgnoreCase(*, null, *) = -1 CharSequenceUtil.indexOfIgnoreCase("", "", 0) = 0 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "A", 0) = 0 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "B", 0) = 2 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "B", 3) = 5 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "B", 9) = -1 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "B", -1) = 2 CharSequenceUtil.indexOfIgnoreCase("aabaabaa", "", 2) = 2 CharSequenceUtil.indexOfIgnoreCase("abc", "", 9) = -1
str
- 字符串searchStr
- 需要查找位置的字符串fromIndex
- 起始位置public static int indexOf(CharSequence text, CharSequence searchStr, int from, boolean ignoreCase)
text
- 字符串,空则返回-1searchStr
- 需要查找位置的字符串,空则返回-1from
- 起始位置(包含)ignoreCase
- 是否忽略大小写public static int lastIndexOfIgnoreCase(CharSequence str, CharSequence searchStr)
str
- 字符串searchStr
- 需要查找位置的字符串public static int lastIndexOfIgnoreCase(CharSequence str, CharSequence searchStr, int fromIndex)
str
- 字符串searchStr
- 需要查找位置的字符串fromIndex
- 起始位置,从后往前计数public static int lastIndexOf(CharSequence text, CharSequence searchStr, int from, boolean ignoreCase)
text
- 字符串searchStr
- 需要查找位置的字符串from
- 起始位置,从后往前计数ignoreCase
- 是否忽略大小写public static int ordinalIndexOf(CharSequence str, CharSequence searchStr, int ordinal)
如果 str=null 或 searchStr=null 或 ordinal≤0 则返回-1
此方法来自:Apache-Commons-Lang
例子(*代表任意字符):
CharSequenceUtil.ordinalIndexOf(null, *, *) = -1 CharSequenceUtil.ordinalIndexOf(*, null, *) = -1 CharSequenceUtil.ordinalIndexOf("", "", *) = 0 CharSequenceUtil.ordinalIndexOf("aabaabaa", "a", 1) = 0 CharSequenceUtil.ordinalIndexOf("aabaabaa", "a", 2) = 1 CharSequenceUtil.ordinalIndexOf("aabaabaa", "b", 1) = 2 CharSequenceUtil.ordinalIndexOf("aabaabaa", "b", 2) = 5 CharSequenceUtil.ordinalIndexOf("aabaabaa", "ab", 1) = 1 CharSequenceUtil.ordinalIndexOf("aabaabaa", "ab", 2) = 4 CharSequenceUtil.ordinalIndexOf("aabaabaa", "", 1) = 0 CharSequenceUtil.ordinalIndexOf("aabaabaa", "", 2) = 0
str
- 被检查的字符串,可以为nullsearchStr
- 被查找的字符串,可以为nullordinal
- 第几次出现的位置public static String removeAll(CharSequence str, CharSequence strToRemove)
str
- 字符串strToRemove
- 被移除的字符串public static String removeAny(CharSequence str, CharSequence... strsToRemove)
str
- 字符串strsToRemove
- 被移除的字符串public static String removeAll(CharSequence str, char... chars)
str
- 字符串chars
- 字符列表public static String removeAllLineBreaks(CharSequence str)
1. \r 1. \n
str
- 字符串public static String removePreAndLowerFirst(CharSequence str, int preLength)
str
- 被处理的字符串preLength
- 去掉的长度public static String removePreAndLowerFirst(CharSequence str, CharSequence prefix)
str
- 被处理的字符串prefix
- 前缀public static String removePrefix(CharSequence str, CharSequence prefix)
str
- 字符串prefix
- 前缀public static String removeAllPrefix(CharSequence str, CharSequence prefix)
str=abcdef, prefix=ab => return cdef
str=ababcdef, prefix=ab => return cdef
str=ababcdef, prefix="" => return ababcdef
str=ababcdef, prefix=null => return ababcdef
str
- 字符串,空返回原字符串prefix
- 前缀,空返回原字符串public static String removePrefixIgnoreCase(CharSequence str, CharSequence prefix)
str
- 字符串prefix
- 前缀public static String removeSuffix(CharSequence str, CharSequence suffix)
str
- 字符串suffix
- 后缀public static String removeAllSuffix(CharSequence str, CharSequence suffix)
str=11abab, suffix=ab => return 11
str=11ab, suffix=ab => return 11
str=11ab, suffix="" => return 11ab
str=11ab, suffix=null => return 11ab
str
- 字符串,空返回原字符串suffix
- 后缀字符串,空返回原字符串public static String removeSufAndLowerFirst(CharSequence str, CharSequence suffix)
str
- 字符串suffix
- 后缀public static String removeSuffixIgnoreCase(CharSequence str, CharSequence suffix)
str
- 字符串suffix
- 后缀public static String cleanBlank(CharSequence str)
str
- 被清理的字符串public static String stripIgnoreCase(CharSequence str, CharSequence prefixOrSuffix)
str
- 被处理的字符串prefixOrSuffix
- 前缀或后缀public static String stripIgnoreCase(CharSequence str, CharSequence prefix, CharSequence suffix)
str
- 被处理的字符串prefix
- 前缀suffix
- 后缀public static String strip(CharSequence str, CharSequence prefixOrSuffix)
str
- 被处理的字符串prefixOrSuffix
- 前缀或后缀public static String strip(CharSequence str, CharSequence prefix, CharSequence suffix)
"aaa_STRIPPED_bbb", "a", "b" -> "aa_STRIPPED_bb"
"aaa_STRIPPED_bbb", null, null -> "aaa_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "", "" -> "aaa_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "", "b" -> "aaa_STRIPPED_bb"
"aaa_STRIPPED_bbb", null, "b" -> "aaa_STRIPPED_bb"
"aaa_STRIPPED_bbb", "a", "" -> "aa_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "a", null -> "aa_STRIPPED_bbb"
"a", "a", "a" -> ""
str
- 被处理的字符串prefix
- 前缀suffix
- 后缀public static String strip(CharSequence str, CharSequence prefix, CharSequence suffix, boolean ignoreCase)
"aaa_STRIPPED_bbb", "a", "b" -> "aa_STRIPPED_bb"
"aaa_STRIPPED_bbb", null, null -> "aaa_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "", "" -> "aaa_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "", "b" -> "aaa_STRIPPED_bb"
"aaa_STRIPPED_bbb", null, "b" -> "aaa_STRIPPED_bb"
"aaa_STRIPPED_bbb", "a", "" -> "aa_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "a", null -> "aa_STRIPPED_bbb"
"a", "a", "a" -> ""
str
- 被处理的字符串prefix
- 前缀suffix
- 后缀ignoreCase
- 是否忽略大小写public static String stripAll(CharSequence str, CharSequence prefixOrSuffix)
"aaa_STRIPPED_bbb", "a" -> "_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "a", "b" -> "_STRIPPED_"
"aaa_STRIPPED_bbb", "" -> "aaa_STRIPPED_bbb"
str
- 被处理的字符串prefixOrSuffix
- 前缀或后缀public static String stripAll(CharSequence str, CharSequence prefix, CharSequence suffix)
"aaa_STRIPPED_bbb", "a", "b" -> "_STRIPPED_"
"aaa_STRIPPED_bbb", null, null -> "aaa_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "", "" -> "aaa_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "", "b" -> "aaa_STRIPPED_"
"aaa_STRIPPED_bbb", null, "b" -> "aaa_STRIPPED_"
"aaa_STRIPPED_bbb", "a", "" -> "_STRIPPED_bbb"
"aaa_STRIPPED_bbb", "a", null -> "_STRIPPED_bbb"
// special test
"aaaaaabbb", "aaa", null -> "bbb"
"aaaaaaabbb", "aa", null -> "abbb"
"aaaaaaaaa", "aaa", "aa" -> ""
"a", "a", "a" -> ""
str
- 被处理的字符串prefix
- 前缀suffix
- 后缀public static String addPrefixIfNot(CharSequence str, CharSequence prefix)
str
- 字符串prefix
- 前缀prependIfMissing(CharSequence, CharSequence, CharSequence...)
public static String addSuffixIfNot(CharSequence str, CharSequence suffix)
str
- 字符串suffix
- 后缀appendIfMissing(CharSequence, CharSequence, CharSequence...)
public static long[] splitToLong(CharSequence str, char separator)
str
- 被切分的字符串separator
- 分隔符public static long[] splitToLong(CharSequence str, CharSequence separator)
str
- 被切分的字符串separator
- 分隔符字符串public static int[] splitToInt(CharSequence str, char separator)
str
- 被切分的字符串separator
- 分隔符public static int[] splitToInt(CharSequence str, CharSequence separator)
str
- 被切分的字符串separator
- 分隔符字符串public static List<String> split(CharSequence str, char separator)
str
- 被切分的字符串separator
- 分隔符字符public static String[] splitToArray(CharSequence str, CharSequence separator)
str
- 被切分的字符串separator
- 分隔符public static String[] splitToArray(CharSequence str, char separator)
str
- 被切分的字符串separator
- 分隔符字符public static String[] splitToArray(CharSequence text, char separator, int limit)
text
- 被切分的字符串separator
- 分隔符字符limit
- 限制分片数public static List<String> split(CharSequence str, char separator, int limit)
str
- 被切分的字符串separator
- 分隔符字符limit
- 限制分片数,-1不限制public static List<String> splitTrim(CharSequence str, char separator)
str
- 被切分的字符串separator
- 分隔符字符public static List<String> splitTrim(CharSequence str, CharSequence separator)
str
- 被切分的字符串separator
- 分隔符字符public static List<String> splitTrim(CharSequence str, char separator, int limit)
str
- 被切分的字符串separator
- 分隔符字符limit
- 限制分片数,-1不限制public static List<String> splitTrim(CharSequence str, CharSequence separator, int limit)
str
- 被切分的字符串separator
- 分隔符字符limit
- 限制分片数,-1不限制public static List<String> split(CharSequence str, char separator, boolean isTrim, boolean ignoreEmpty)
str
- 被切分的字符串separator
- 分隔符字符isTrim
- 是否去除切分字符串后每个元素两边的空格ignoreEmpty
- 是否忽略空串public static List<String> split(CharSequence str, char separator, int limit, boolean isTrim, boolean ignoreEmpty)
str
- 被切分的字符串separator
- 分隔符字符limit
- 限制分片数,-1不限制isTrim
- 是否去除切分字符串后每个元素两边的空格ignoreEmpty
- 是否忽略空串public static <R> List<R> split(CharSequence str, char separator, int limit, boolean ignoreEmpty, Function<String,R> mapping)
R
- 切分后元素类型str
- 被切分的字符串separator
- 分隔符字符limit
- 限制分片数,-1不限制ignoreEmpty
- 是否忽略空串mapping
- 切分后的字符串元素的转换方法public static List<String> split(CharSequence str, CharSequence separator)
str
- 被切分的字符串separator
- 分隔符public static List<String> split(CharSequence str, CharSequence separator, boolean isTrim, boolean ignoreEmpty)
str
- 被切分的字符串separator
- 分隔符字符isTrim
- 是否去除切分字符串后每个元素两边的空格ignoreEmpty
- 是否忽略空串public static List<String> split(CharSequence str, CharSequence separator, int limit, boolean isTrim, boolean ignoreEmpty)
str
- 被切分的字符串separator
- 分隔符字符limit
- 限制分片数,-1不限制isTrim
- 是否去除切分字符串后每个元素两边的空格ignoreEmpty
- 是否忽略空串public static String[] split(CharSequence str, int len)
str
- 字符串len
- 每一个小节的长度StrSplitter.splitByLength(CharSequence, int)
public static String[] cut(CharSequence str, int partLength)
str
- 字符串partLength
- 每等份的长度public static String sub(CharSequence str, int fromIndexInclude, int toIndexExclude)
str
- StringfromIndexInclude
- 开始的index(包括)toIndexExclude
- 结束的index(不包括)public static String subByCodePoint(CharSequence str, int fromIndex, int toIndex)
str
- StringfromIndex
- 开始的index(包括)toIndex
- 结束的index(不包括)public static String subPreGbk(CharSequence str, int len, CharSequence suffix)
str
- 字符串len
- bytes切割到的位置(包含)suffix
- 切割后加上后缀public static String subPreGbk(CharSequence str, int len, boolean halfUp)
true
表示保留,则长度是11,否则长度9str
- 字符串len
- bytes切割到的位置(包含)halfUp
- 遇到截取一半的GBK字符,是否保留。public static String subPre(CharSequence string, int toIndexExclude)
string
- 字符串toIndexExclude
- 切割到的位置(不包括)public static String subSuf(CharSequence string, int fromIndex)
string
- 字符串fromIndex
- 切割开始的位置(包括)public static String subSufByLength(CharSequence string, int length)
CharSequenceUtil.subSufByLength("abcde", 3) = "cde" CharSequenceUtil.subSufByLength("abcde", 0) = "" CharSequenceUtil.subSufByLength("abcde", -5) = "" CharSequenceUtil.subSufByLength("abcde", -1) = "" CharSequenceUtil.subSufByLength("abcde", 5) = "abcde" CharSequenceUtil.subSufByLength("abcde", 10) = "abcde" CharSequenceUtil.subSufByLength(null, 3) = null
string
- 字符串length
- 切割长度public static String subWithLength(String input, int fromIndex, int length)
input
- 原始字符串fromIndex
- 开始的index,包括length
- 要截取的长度public static String subBefore(CharSequence string, CharSequence separator, boolean isLastSeparator)
CharSequenceUtil.subBefore(null, *, false) = null CharSequenceUtil.subBefore("", *, false) = "" CharSequenceUtil.subBefore("abc", "a", false) = "" CharSequenceUtil.subBefore("abcba", "b", false) = "a" CharSequenceUtil.subBefore("abc", "c", false) = "ab" CharSequenceUtil.subBefore("abc", "d", false) = "abc" CharSequenceUtil.subBefore("abc", "", false) = "" CharSequenceUtil.subBefore("abc", null, false) = "abc"
string
- 被查找的字符串separator
- 分隔字符串(不包括)isLastSeparator
- 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个public static String subBefore(CharSequence string, char separator, boolean isLastSeparator)
CharSequenceUtil.subBefore(null, *, false) = null CharSequenceUtil.subBefore("", *, false) = "" CharSequenceUtil.subBefore("abc", 'a', false) = "" CharSequenceUtil.subBefore("abcba", 'b', false) = "a" CharSequenceUtil.subBefore("abc", 'c', false) = "ab" CharSequenceUtil.subBefore("abc", 'd', false) = "abc"
string
- 被查找的字符串separator
- 分隔字符串(不包括)isLastSeparator
- 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个public static String subAfter(CharSequence string, CharSequence separator, boolean isLastSeparator)
CharSequenceUtil.subAfter(null, *, false) = null CharSequenceUtil.subAfter("", *, false) = "" CharSequenceUtil.subAfter(*, null, false) = "" CharSequenceUtil.subAfter("abc", "a", false) = "bc" CharSequenceUtil.subAfter("abcba", "b", false) = "cba" CharSequenceUtil.subAfter("abc", "c", false) = "" CharSequenceUtil.subAfter("abc", "d", false) = "" CharSequenceUtil.subAfter("abc", "", false) = "abc"
string
- 被查找的字符串separator
- 分隔字符串(不包括)isLastSeparator
- 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个public static String subAfter(CharSequence string, char separator, boolean isLastSeparator)
CharSequenceUtil.subAfter(null, *, false) = null CharSequenceUtil.subAfter("", *, false) = "" CharSequenceUtil.subAfter("abc", 'a', false) = "bc" CharSequenceUtil.subAfter("abcba", 'b', false) = "cba" CharSequenceUtil.subAfter("abc", 'c', false) = "" CharSequenceUtil.subAfter("abc", 'd', false) = ""
string
- 被查找的字符串separator
- 分隔字符串(不包括)isLastSeparator
- 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个public static String subBetween(CharSequence str, CharSequence before, CharSequence after)
栗子:
CharSequenceUtil.subBetween("wx[b]yz", "[", "]") = "b" CharSequenceUtil.subBetween(null, *, *) = null CharSequenceUtil.subBetween(*, null, *) = null CharSequenceUtil.subBetween(*, *, null) = null CharSequenceUtil.subBetween("", "", "") = "" CharSequenceUtil.subBetween("", "", "]") = null CharSequenceUtil.subBetween("", "[", "]") = null CharSequenceUtil.subBetween("yabcz", "", "") = "" CharSequenceUtil.subBetween("yabcz", "y", "z") = "abc" CharSequenceUtil.subBetween("yabczyabcz", "y", "z") = "abc"
str
- 被切割的字符串before
- 截取开始的字符串标识after
- 截取到的字符串标识public static String subBetween(CharSequence str, CharSequence beforeAndAfter)
栗子:
CharSequenceUtil.subBetween(null, *) = null CharSequenceUtil.subBetween("", "") = "" CharSequenceUtil.subBetween("", "tag") = null CharSequenceUtil.subBetween("tagabctag", null) = null CharSequenceUtil.subBetween("tagabctag", "") = "" CharSequenceUtil.subBetween("tagabctag", "tag") = "abc"
str
- 被切割的字符串beforeAndAfter
- 截取开始和结束的字符串标识public static String[] subBetweenAll(CharSequence str, CharSequence prefix, CharSequence suffix)
栗子:
CharSequenceUtil.subBetweenAll("wx[b]y[z]", "[", "]") = ["b","z"] CharSequenceUtil.subBetweenAll(null, *, *) = [] CharSequenceUtil.subBetweenAll(*, null, *) = [] CharSequenceUtil.subBetweenAll(*, *, null) = [] CharSequenceUtil.subBetweenAll("", "", "") = [] CharSequenceUtil.subBetweenAll("", "", "]") = [] CharSequenceUtil.subBetweenAll("", "[", "]") = [] CharSequenceUtil.subBetweenAll("yabcz", "", "") = [] CharSequenceUtil.subBetweenAll("yabcz", "y", "z") = ["abc"] CharSequenceUtil.subBetweenAll("yabczyabcz", "y", "z") = ["abc","abc"] CharSequenceUtil.subBetweenAll("[yabc[zy]abcz]", "[", "]"); = ["zy"] 重叠时只截取内部,
str
- 被切割的字符串prefix
- 截取开始的字符串标识suffix
- 截取到的字符串标识public static String[] subBetweenAll(CharSequence str, CharSequence prefixAndSuffix)
栗子:
CharSequenceUtil.subBetweenAll(null, *) = [] CharSequenceUtil.subBetweenAll(*, null) = [] CharSequenceUtil.subBetweenAll(*, *) = [] CharSequenceUtil.subBetweenAll("", "") = [] CharSequenceUtil.subBetweenAll("", "#") = [] CharSequenceUtil.subBetweenAll("gotanks", "") = [] CharSequenceUtil.subBetweenAll("#gotanks#", "#") = ["gotanks"] CharSequenceUtil.subBetweenAll("#hello# #world#!", "#") = ["hello", "world"] CharSequenceUtil.subBetweenAll("#hello# world#!", "#"); = ["hello"]
str
- 被切割的字符串prefixAndSuffix
- 截取开始和结束的字符串标识public static String repeat(char c, int count)
CharSequenceUtil.repeat('e', 0) = "" CharSequenceUtil.repeat('e', 3) = "eee" CharSequenceUtil.repeat('e', -2) = ""
c
- 被重复的字符count
- 重复的数目,如果小于等于0则返回""public static String repeat(CharSequence str, int count)
str
- 被重复的字符count
- 重复的数目public static String repeatByLength(CharSequence str, int padLen)
str
- 被重复的字符padLen
- 指定长度public static String repeatAndJoin(CharSequence str, int count, CharSequence delimiter)
CharSequenceUtil.repeatAndJoin("?", 5, ",") = "?,?,?,?,?" CharSequenceUtil.repeatAndJoin("?", 0, ",") = "" CharSequenceUtil.repeatAndJoin("?", 5, null) = "?????"
str
- 被重复的字符串count
- 数量delimiter
- 分界符public static boolean equals(CharSequence str1, CharSequence str2)
equals(null, null) = true equals(null, "abc") = false equals("abc", null) = false equals("abc", "abc") = true equals("abc", "ABC") = false
str1
- 要比较的字符串1str2
- 要比较的字符串2null
,则返回true
public static boolean equalsIgnoreCase(CharSequence str1, CharSequence str2)
equalsIgnoreCase(null, null) = true equalsIgnoreCase(null, "abc") = false equalsIgnoreCase("abc", null) = false equalsIgnoreCase("abc", "abc") = true equalsIgnoreCase("abc", "ABC") = true
str1
- 要比较的字符串1str2
- 要比较的字符串2null
,则返回true
public static boolean equals(CharSequence str1, CharSequence str2, boolean ignoreCase)
null
String.equalsIgnoreCase(String)
判断相等String.contentEquals(CharSequence)
判断相等str1
- 要比较的字符串1str2
- 要比较的字符串2ignoreCase
- 是否忽略大小写null
,则返回true
public static boolean equalsAnyIgnoreCase(CharSequence str1, CharSequence... strs)
true
,没有相同的返回false
false
str1
- 给定需要检查的字符串strs
- 需要参与比对的字符串列表public static boolean equalsAny(CharSequence str1, CharSequence... strs)
true
,没有相同的返回false
false
str1
- 给定需要检查的字符串strs
- 需要参与比对的字符串列表public static boolean equalsAny(CharSequence str1, boolean ignoreCase, CharSequence... strs)
true
,没有相同的返回false
false
str1
- 给定需要检查的字符串ignoreCase
- 是否忽略大小写strs
- 需要参与比对的字符串列表public static boolean equalsCharAt(CharSequence str, int position, char c)
str
- 字符串position
- 位置c
- 需要对比的字符public static boolean isSubEquals(CharSequence str1, int start1, CharSequence str2, boolean ignoreCase)
str1
- 第一个字符串start1
- 第一个字符串开始的位置str2
- 第二个字符串ignoreCase
- 是否忽略大小写public static boolean isSubEquals(CharSequence str1, int start1, CharSequence str2, int start2, int length, boolean ignoreCase)
str1
- 第一个字符串start1
- 第一个字符串开始的位置str2
- 第二个字符串start2
- 第二个字符串开始的位置length
- 截取长度ignoreCase
- 是否忽略大小写public static String format(CharSequence template, Object... params)
template
- 文本模板,被替换的部分用 {} 表示,如果模板为null,返回"null"params
- 参数值public static String indexedFormat(CharSequence pattern, Object... arguments)
pattern
- 文本格式arguments
- 参数public static byte[] utf8Bytes(CharSequence str)
str
- 字符串public static byte[] bytes(CharSequence str)
str
- 字符串public static byte[] bytes(CharSequence str, String charset)
str
- 字符串charset
- 字符集,如果此字段为空,则解码的结果取决于平台public static byte[] bytes(CharSequence str, Charset charset)
str
- 字符串charset
- 字符集,如果此字段为空,则解码的结果取决于平台public static ByteBuffer byteBuffer(CharSequence str, String charset)
str
- 字符串charset
- 编码public static String wrap(CharSequence str, CharSequence prefixAndSuffix)
str
- 被包装的字符串prefixAndSuffix
- 前缀和后缀public static String wrap(CharSequence str, CharSequence prefix, CharSequence suffix)
str
- 被包装的字符串prefix
- 前缀suffix
- 后缀public static String[] wrapAllWithPair(CharSequence prefixAndSuffix, CharSequence... strs)
prefixAndSuffix
- 前缀和后缀strs
- 多个字符串public static String[] wrapAll(CharSequence prefix, CharSequence suffix, CharSequence... strs)
prefix
- 前缀suffix
- 后缀strs
- 多个字符串public static String wrapIfMissing(CharSequence str, CharSequence prefix, CharSequence suffix)
str
- 被包装的字符串prefix
- 前缀suffix
- 后缀public static String[] wrapAllWithPairIfMissing(CharSequence prefixAndSuffix, CharSequence... strs)
prefixAndSuffix
- 前缀和后缀strs
- 多个字符串public static String[] wrapAllIfMissing(CharSequence prefix, CharSequence suffix, CharSequence... strs)
prefix
- 前缀suffix
- 后缀strs
- 多个字符串public static String unWrap(CharSequence str, String prefix, String suffix)
str
- 字符串prefix
- 前置字符串suffix
- 后置字符串public static String unWrap(CharSequence str, char prefix, char suffix)
str
- 字符串prefix
- 前置字符suffix
- 后置字符public static String unWrap(CharSequence str, char prefixAndSuffix)
str
- 字符串prefixAndSuffix
- 前置和后置字符public static boolean isWrap(CharSequence str, String prefix, String suffix)
str
- 字符串prefix
- 前缀suffix
- 后缀public static boolean isWrap(CharSequence str, String wrapper)
str
- 字符串wrapper
- 包装字符串public static boolean isWrap(CharSequence str, char wrapper)
str
- 字符串wrapper
- 包装字符public static boolean isWrap(CharSequence str, char prefixChar, char suffixChar)
str
- 字符串prefixChar
- 前缀suffixChar
- 后缀public static String padPre(CharSequence str, int length, CharSequence padStr)
CharSequenceUtil.padPre(null, *, *);//null CharSequenceUtil.padPre("1", 3, "ABC");//"AB1" CharSequenceUtil.padPre("123", 2, "ABC");//"12" CharSequenceUtil.padPre("1039", -1, "0");//"103"
str
- 字符串length
- 长度padStr
- 补充的字符public static String padPre(CharSequence str, int length, char padChar)
CharSequenceUtil.padPre(null, *, *);//null CharSequenceUtil.padPre("1", 3, '0');//"001" CharSequenceUtil.padPre("123", 2, '0');//"12"
str
- 字符串length
- 长度padChar
- 补充的字符public static String padAfter(CharSequence str, int length, char padChar)
CharSequenceUtil.padAfter(null, *, *);//null CharSequenceUtil.padAfter("1", 3, '0');//"100" CharSequenceUtil.padAfter("123", 2, '0');//"23" CharSequenceUtil.padAfter("123", -1, '0')//"" 空串
str
- 字符串,如果为null
,直接返回nulllength
- 长度padChar
- 补充的字符public static String padAfter(CharSequence str, int length, CharSequence padStr)
CharSequenceUtil.padAfter(null, *, *);//null CharSequenceUtil.padAfter("1", 3, "ABC");//"1AB" CharSequenceUtil.padAfter("123", 2, "ABC");//"23"
str
- 字符串,如果为null
,直接返回nulllength
- 长度padStr
- 补充的字符public static String center(CharSequence str, int size)
CharSequenceUtil.center(null, *) = null CharSequenceUtil.center("", 4) = " " CharSequenceUtil.center("ab", -1) = "ab" CharSequenceUtil.center("ab", 4) = " ab " CharSequenceUtil.center("abcd", 2) = "abcd" CharSequenceUtil.center("a", 4) = " a "
str
- 字符串size
- 指定长度public static String center(CharSequence str, int size, char padChar)
CharSequenceUtil.center(null, *, *) = null CharSequenceUtil.center("", 4, ' ') = " " CharSequenceUtil.center("ab", -1, ' ') = "ab" CharSequenceUtil.center("ab", 4, ' ') = " ab " CharSequenceUtil.center("abcd", 2, ' ') = "abcd" CharSequenceUtil.center("a", 4, ' ') = " a " CharSequenceUtil.center("a", 4, 'y') = "yayy" CharSequenceUtil.center("abc", 7, ' ') = " abc "
str
- 字符串size
- 指定长度padChar
- 两边补充的字符public static String center(CharSequence str, int size, CharSequence padStr)
CharSequenceUtil.center(null, *, *) = null CharSequenceUtil.center("", 4, " ") = " " CharSequenceUtil.center("ab", -1, " ") = "ab" CharSequenceUtil.center("ab", 4, " ") = " ab " CharSequenceUtil.center("abcd", 2, " ") = "abcd" CharSequenceUtil.center("a", 4, " ") = " a " CharSequenceUtil.center("a", 4, "yz") = "yayz" CharSequenceUtil.center("abc", 7, null) = " abc " CharSequenceUtil.center("abc", 7, "") = " abc "
str
- 字符串size
- 指定长度padStr
- 两边补充的字符串public static String str(CharSequence cs)
CharSequence
转为字符串,null安全cs
- CharSequence
public static int count(CharSequence content, CharSequence strForSearch)
null
或者 "" 返回 0
.
CharSequenceUtil.count(null, *) = 0 CharSequenceUtil.count("", *) = 0 CharSequenceUtil.count("abba", null) = 0 CharSequenceUtil.count("abba", "") = 0 CharSequenceUtil.count("abba", "a") = 2 CharSequenceUtil.count("abba", "ab") = 1 CharSequenceUtil.count("abba", "xxx") = 0
content
- 被查找的字符串strForSearch
- 需要查找的字符串public static int count(CharSequence content, char charForSearch)
content
- 内容charForSearch
- 被统计的字符public static int compare(CharSequence str1, CharSequence str2, boolean nullIsLess)
CharSequenceUtil.compare(null, null, *) = 0 CharSequenceUtil.compare(null , "a", true) < 0 CharSequenceUtil.compare(null , "a", false) > 0 CharSequenceUtil.compare("a", null, true) > 0 CharSequenceUtil.compare("a", null, false) < 0 CharSequenceUtil.compare("abc", "abc", *) = 0 CharSequenceUtil.compare("a", "b", *) < 0 CharSequenceUtil.compare("b", "a", *) > 0 CharSequenceUtil.compare("a", "B", *) > 0 CharSequenceUtil.compare("ab", "abc", *) < 0
str1
- 字符串1str2
- 字符串2nullIsLess
- null
值是否排在前(null是否小于非空值)public static int compareIgnoreCase(CharSequence str1, CharSequence str2, boolean nullIsLess)
CharSequenceUtil.compareIgnoreCase(null, null, *) = 0 CharSequenceUtil.compareIgnoreCase(null , "a", true) < 0 CharSequenceUtil.compareIgnoreCase(null , "a", false) > 0 CharSequenceUtil.compareIgnoreCase("a", null, true) > 0 CharSequenceUtil.compareIgnoreCase("a", null, false) < 0 CharSequenceUtil.compareIgnoreCase("abc", "abc", *) = 0 CharSequenceUtil.compareIgnoreCase("abc", "ABC", *) = 0 CharSequenceUtil.compareIgnoreCase("a", "b", *) < 0 CharSequenceUtil.compareIgnoreCase("b", "a", *) > 0 CharSequenceUtil.compareIgnoreCase("a", "B", *) < 0 CharSequenceUtil.compareIgnoreCase("A", "b", *) < 0 CharSequenceUtil.compareIgnoreCase("ab", "abc", *) < 0
str1
- 字符串1str2
- 字符串2nullIsLess
- null
值是否排在前(null是否小于非空值)public static int compareVersion(CharSequence version1, CharSequence version2)
CharSequenceUtil.compareVersion(null, "v1") < 0 CharSequenceUtil.compareVersion("v1", "v1") = 0 CharSequenceUtil.compareVersion(null, null) = 0 CharSequenceUtil.compareVersion("v1", null) > 0 CharSequenceUtil.compareVersion("1.0.0", "1.0.2") < 0 CharSequenceUtil.compareVersion("1.0.2", "1.0.2a") < 0 CharSequenceUtil.compareVersion("1.13.0", "1.12.1c") > 0 CharSequenceUtil.compareVersion("V0.0.20170102", "V0.0.20170101") > 0
version1
- 版本1version2
- 版本2public static String appendIfMissing(CharSequence str, CharSequence suffix, CharSequence... suffixes)
str
- 被检查的字符串suffix
- 需要添加到结尾的字符串suffixes
- 需要额外检查的结尾字符串,如果以这些中的一个为结尾,则不再添加public static String appendIfMissingIgnoreCase(CharSequence str, CharSequence suffix, CharSequence... suffixes)
str
- 被检查的字符串suffix
- 需要添加到结尾的字符串suffixes
- 需要额外检查的结尾字符串,如果以这些中的一个为结尾,则不再添加public static String appendIfMissing(CharSequence str, CharSequence suffix, boolean ignoreCase, CharSequence... testSuffixes)
str
- 被检查的字符串suffix
- 需要添加到结尾的字符串,不参与检查匹配ignoreCase
- 检查结尾时是否忽略大小写testSuffixes
- 需要额外检查的结尾字符串,如果以这些中的一个为结尾,则不再添加public static String prependIfMissing(CharSequence str, CharSequence prefix, CharSequence... prefixes)
str
- 被检查的字符串prefix
- 需要添加到首部的字符串prefixes
- 需要额外检查的首部字符串,如果以这些中的一个为起始,则不再添加public static String prependIfMissingIgnoreCase(CharSequence str, CharSequence prefix, CharSequence... prefixes)
str
- 被检查的字符串prefix
- 需要添加到首部的字符串prefixes
- 需要额外检查的首部字符串,如果以这些中的一个为起始,则不再添加public static String prependIfMissing(CharSequence str, CharSequence prefix, boolean ignoreCase, CharSequence... prefixes)
str
- 被检查的字符串prefix
- 需要添加到首部的字符串ignoreCase
- 检查结尾时是否忽略大小写prefixes
- 需要额外检查的首部字符串,如果以这些中的一个为起始,则不再添加public static String replaceIgnoreCase(CharSequence str, CharSequence searchStr, CharSequence replacement)
str
- 字符串searchStr
- 被查找的字符串replacement
- 被替换的字符串public static String replace(CharSequence str, CharSequence searchStr, CharSequence replacement)
str
- 字符串searchStr
- 被查找的字符串replacement
- 被替换的字符串public static String replace(CharSequence str, CharSequence searchStr, CharSequence replacement, boolean ignoreCase)
str
- 字符串searchStr
- 被查找的字符串replacement
- 被替换的字符串ignoreCase
- 是否忽略大小写public static String replace(CharSequence str, int fromIndex, CharSequence searchStr, CharSequence replacement, boolean ignoreCase)
str
- 字符串fromIndex
- 开始位置(包括)searchStr
- 被查找的字符串replacement
- 被替换的字符串ignoreCase
- 是否忽略大小写@Deprecated public static String replace(CharSequence str, int startInclude, int endExclude, char replacedChar)
replaceByCodePoint(CharSequence, int, int, char)
CharSequence.codePoints()
完成拆分替换str
- 字符串startInclude
- 开始位置(包含)endExclude
- 结束位置(不包含)replacedChar
- 被替换的字符public static String replaceByCodePoint(CharSequence str, int startInclude, int endExclude, char replacedChar)
CharSequence.codePoints()
完成拆分替换str
- 字符串startInclude
- 开始位置(包含)endExclude
- 结束位置(不包含)replacedChar
- 被替换的字符@Deprecated public static String replace(CharSequence str, int startInclude, int endExclude, CharSequence replacedStr)
replaceByCodePoint(CharSequence, int, int, CharSequence)
CharSequence.codePoints()
完成拆分替换str
- 字符串startInclude
- 开始位置(包含)endExclude
- 结束位置(不包含)replacedStr
- 被替换的字符串public static String replaceByCodePoint(CharSequence str, int startInclude, int endExclude, CharSequence replacedStr)
CharSequence.codePoints()
完成拆分替换str
- 字符串startInclude
- 开始位置(包含)endExclude
- 结束位置(不包含)replacedStr
- 被替换的字符串public static String replace(CharSequence str, Pattern pattern, Func1<Matcher,String> replaceFun)
Matcher
提取出匹配到的内容的不同部分,然后经过重新处理、组装变成新的内容放回原位。
replace(this.content, "(\\d+)", parameters -> "-" + parameters.group(1) + "-") // 结果为:"ZZZaaabbbccc中文-1234-"
str
- 要替换的字符串pattern
- 用于匹配的正则式replaceFun
- 决定如何替换的函数ReUtil.replaceAll(CharSequence, java.util.regex.Pattern, Func1)
public static String replace(CharSequence str, String regex, Func1<Matcher,String> replaceFun)
str
- 要替换的字符串regex
- 用于匹配的正则式replaceFun
- 决定如何替换的函数ReUtil.replaceAll(CharSequence, String, Func1)
public static String replaceLast(CharSequence str, CharSequence searchStr, CharSequence replacedStr)
str
- 字符串searchStr
- 被查找的字符串replacedStr
- 被替换的字符串public static String replaceLast(CharSequence str, CharSequence searchStr, CharSequence replacedStr, boolean ignoreCase)
str
- 字符串searchStr
- 被查找的字符串replacedStr
- 被替换的字符串ignoreCase
- 是否忽略大小写public static String replaceFirst(CharSequence str, CharSequence searchStr, CharSequence replacedStr)
str
- 字符串searchStr
- 被查找的字符串replacedStr
- 被替换的字符串public static String replaceFirst(CharSequence str, CharSequence searchStr, CharSequence replacedStr, boolean ignoreCase)
str
- 字符串searchStr
- 被查找的字符串replacedStr
- 被替换的字符串ignoreCase
- 是否忽略大小写public static String hide(CharSequence str, int startInclude, int endExclude)
CharSequenceUtil.hide(null,*,*)=null CharSequenceUtil.hide("",0,*)="" CharSequenceUtil.hide("jackduan@163.com",-1,4) ****duan@163.com CharSequenceUtil.hide("jackduan@163.com",2,3) ja*kduan@163.com CharSequenceUtil.hide("jackduan@163.com",3,2) jackduan@163.com CharSequenceUtil.hide("jackduan@163.com",16,16) jackduan@163.com CharSequenceUtil.hide("jackduan@163.com",16,17) jackduan@163.com
str
- 字符串startInclude
- 开始位置(包含)endExclude
- 结束位置(不包含)public static String desensitized(CharSequence str, DesensitizedUtil.DesensitizedType desensitizedType)
CharSequenceUtil.desensitized("100", DesensitizedUtil.DesensitizedType.USER_ID)) = "0" CharSequenceUtil.desensitized("段正淳", DesensitizedUtil.DesensitizedType.CHINESE_NAME)) = "段**" CharSequenceUtil.desensitized("51343620000320711X", DesensitizedUtil.DesensitizedType.ID_CARD)) = "5***************1X" CharSequenceUtil.desensitized("09157518479", DesensitizedUtil.DesensitizedType.FIXED_PHONE)) = "0915*****79" CharSequenceUtil.desensitized("18049531999", DesensitizedUtil.DesensitizedType.MOBILE_PHONE)) = "180****1999" CharSequenceUtil.desensitized("北京市海淀区马连洼街道289号", DesensitizedUtil.DesensitizedType.ADDRESS)) = "北京市海淀区马********" CharSequenceUtil.desensitized("duandazhi-jack@gmail.com.cn", DesensitizedUtil.DesensitizedType.EMAIL)) = "d*************@gmail.com.cn" CharSequenceUtil.desensitized("1234567890", DesensitizedUtil.DesensitizedType.PASSWORD)) = "**********" CharSequenceUtil.desensitized("苏D40000", DesensitizedUtil.DesensitizedType.CAR_LICENSE)) = "苏D4***0" CharSequenceUtil.desensitized("11011111222233333256", DesensitizedType.BANK_CARD)) = "1101 **** **** **** 3256"
str
- 字符串desensitizedType
- 脱敏类型;可以脱敏:用户id、中文名、身份证号、座机号、手机号、地址、电子邮件、密码如果需要自定义,脱敏规则,请使用该工具类;
public static String replaceChars(CharSequence str, String chars, CharSequence replacedStr)
str
- 被检查的字符串chars
- 需要替换的字符列表,用一个字符串表示这个字符列表replacedStr
- 替换成的字符串public static String replaceChars(CharSequence str, char[] chars, CharSequence replacedStr)
str
- 被检查的字符串chars
- 需要替换的字符列表replacedStr
- 替换成的字符串public static int length(CharSequence cs)
cs
- a 字符串public static int byteLength(CharSequence cs, Charset charset)
cs
- 字符串charset
- 编码public static int totalLength(CharSequence... strs)
strs
- 字符串数组public static String maxLength(CharSequence string, int length)
string
- 字符串length
- 最大长度public static <T extends CharSequence> T firstNonNull(T... strs)
null
元素T
- 元素类型strs
- 多个元素null
public static <T extends CharSequence> T firstNonEmpty(T... strs)
T
- 元素类型strs
- 多个元素null
isNotEmpty(CharSequence)
public static <T extends CharSequence> T firstNonBlank(T... strs)
T
- 元素类型strs
- 多个元素null
isNotBlank(CharSequence)
public static String upperFirstAndAddPre(CharSequence str, String preString)
str
- 被处理的字符串preString
- 添加的首部public static String upperFirst(CharSequence str)
str
- 字符串public static String lowerFirst(CharSequence str)
str
- 字符串public static String filter(CharSequence str, Filter<Character> filter)
str
- 字符串filter
- 过滤器,Filter.accept(Object)
返回为true
的保留字符public static boolean isUpperCase(CharSequence str)
1. 大写字母包括A-Z 2. 其它非字母的Unicode符都算作大写
str
- 被检查的字符串public static boolean isLowerCase(CharSequence str)
1. 小写字母包括a-z 2. 其它非字母的Unicode符都算作小写
str
- 被检查的字符串public static String swapCase(String str)
CharSequenceUtil.swapCase(null) = null CharSequenceUtil.swapCase("") = "" CharSequenceUtil.swapCase("The dog has a BONE") = "tHE DOG HAS A bone"
str
- 字符串public static String toUnderlineCase(CharSequence str)
HelloWorld=》hello_world Hello_World=》hello_world HelloWorld_test=》hello_world_test
str
- 转换前的驼峰式命名的字符串,也可以为下划线形式NamingCase.toUnderlineCase(CharSequence)
public static String toSymbolCase(CharSequence str, char symbol)
str
- 转换前的驼峰式命名的字符串,也可以为符号连接形式symbol
- 连接符NamingCase.toSymbolCase(CharSequence, char)
public static String toCamelCase(CharSequence name)
name
- 转换前的下划线大写方式命名的字符串NamingCase.toCamelCase(CharSequence)
public static String toCamelCase(CharSequence name, char symbol)
name
- 转换前的下划线大写方式命名的字符串symbol
- 连接符NamingCase.toCamelCase(CharSequence, char)
public static boolean isSurround(CharSequence str, CharSequence prefix, CharSequence suffix)
str
- 字符串prefix
- 前缀suffix
- 后缀public static boolean isSurround(CharSequence str, char prefix, char suffix)
str
- 字符串prefix
- 前缀suffix
- 后缀public static StringBuilder builder(CharSequence... strs)
strs
- 初始字符串列表public static StrBuilder strBuilder(CharSequence... strs)
strs
- 初始字符串列表public static String getGeneralField(CharSequence getOrSetMethodName)
getName =》name setName =》name isName =》name
getOrSetMethodName
- Get或Set方法名public static String genSetter(CharSequence fieldName)
fieldName
- 属性名public static String genGetter(CharSequence fieldName)
fieldName
- 属性名public static String concat(boolean isNullToEmpty, CharSequence... strs)
isNullToEmpty
- 是否null转为""strs
- 字符串数组public static String brief(CharSequence str, int maxLength)
str
- 字符串maxLength
- 结果的最大长度public static String join(CharSequence conjunction, Object... objs)
conjunction
- 分隔符 StrPool.COMMA
objs
- 数组ArrayUtil.join(Object, CharSequence)
public static <T> String join(CharSequence conjunction, Iterable<T> iterable)
T
- 元素类型conjunction
- 分隔符 StrPool.COMMA
iterable
- 集合CollUtil.join(Iterable, CharSequence)
public static boolean isAllCharMatch(CharSequence value, Matcher<Character> matcher)
value
- 字符串matcher
- 匹配器public static boolean isNumeric(CharSequence str)
str
- 字符串public static String move(CharSequence str, int startInclude, int endExclude, int moveLength)
str
- 字符串startInclude
- 起始位置(包括)endExclude
- 结束位置(不包括)moveLength
- 移动距离,负数表示左移,正数为右移public static boolean isCharEquals(CharSequence str)
str
- 字符出啊public static String normalize(CharSequence str)
str
- 归一化的字符串Normalizer.normalize(CharSequence, Normalizer.Form)
public static String fixLength(CharSequence str, char fixedChar, int length)
str
- 字符串fixedChar
- 补充的字符length
- 补充到的长度public static boolean hasLetter(CharSequence str)
指定字符串数组中,是否包含空字符串。
如果传入参数对象不是为空,则返回false。如果字符串包含字母,不区分大小写,则返回true
str
- 对象public static CharSequence commonPrefix(CharSequence str1, CharSequence str2)
str1
- 字符串1str2
- 字符串2public static CharSequence commonSuffix(CharSequence str1, CharSequence str2)
str1
- 字符串1str2
- 字符串2Copyright © 2024. All rights reserved.