| Constructor and Description |
|---|
CharsKit() |
| Modifier and Type | Method and Description |
|---|---|
static String |
addPrefixIfNot(CharSequence text,
CharSequence prefix)
如果给定字符串不是以prefix开头的,在开头补充 prefix
|
static String |
addSuffixIfNot(CharSequence text,
CharSequence suffix)
如果给定字符串不是以suffix结尾的,在尾部补充 suffix
|
static String |
appendIfMissing(String text,
CharSequence suffix,
CharSequence... suffixes)
如果字符串还没有以任何后缀结尾,则将后缀追加到字符串的末尾.
|
static String |
appendIfMissingIgnoreCase(String text,
CharSequence suffix,
CharSequence... suffixes)
如果字符串还没有结束,则使用任何后缀将后缀追加到字符串的末尾,不区分大小写.
|
static String |
blankToDefault(CharSequence text,
String defaultStr)
如果字符串是
null或者""或者空白,则返回指定默认字符串,否则返回字符串本身。 |
static String |
brief(CharSequence text,
int maxLength)
将给定字符串,变成 "xxx...xxx" 形式的字符串
abcdef 5 -》 a...f
abcdef 4 -》 a..f
abcdef 3 -》 a.f
abcdef 2 -》 a.
abcdef 1 -》 a
|
static StringBuilder |
builder(CharSequence... text)
创建StringBuilder对象
|
static int |
byteLength(CharSequence cs,
Charset charset)
给定字符串转为bytes后的byte数(byte长度)
|
static byte[] |
bytes(CharSequence text)
编码字符串
使用系统默认编码
|
static byte[] |
bytes(CharSequence text,
Charset charset)
编码字符串
|
static byte[] |
bytes(CharSequence text,
String charset)
编码字符串
|
static char |
byteToChar(byte[] b)
byte转car
|
static String |
center(CharSequence text,
int size)
居中字符串,两边补充指定字符串,如果指定长度小于字符串,则返回原字符串
|
static String |
center(CharSequence text,
int size,
char padChar)
居中字符串,两边补充指定字符串,如果指定长度小于字符串,则返回原字符串
|
static String |
center(CharSequence text,
int size,
CharSequence padStr)
居中字符串,两边补充指定字符串,如果指定长度小于字符串,则返回原字符串
|
static String |
cleanBlank(CharSequence text)
清理空白字符
|
static int |
compare(char x,
char y)
对两个
char值进行数值比较 |
static boolean |
contains(CharSequence text,
char searchChar)
指定字符是否在字符串中出现过
|
static boolean |
contains(CharSequence text,
CharSequence word)
指定字符串是否在字符串中出现过
|
static boolean |
containsAny(CharSequence text,
char... testChars)
查找指定字符串是否包含指定字符列表中的任意一个字符
|
static boolean |
containsAny(CharSequence text,
CharSequence... testStrs)
查找指定字符串是否包含指定字符串列表中的任意一个字符串
|
static boolean |
containsAnyIgnoreCase(CharSequence text,
CharSequence... testStrs)
查找指定字符串是否包含指定字符串列表中的任意一个字符串
忽略大小写
|
static boolean |
containsBlank(CharSequence text)
给定字符串是否包含空白符(空白符包括空格、制表符、全角空格和不间断空格)
如果给定字符串为null或者"",则返回false
|
static boolean |
containsIgnoreCase(CharSequence text,
CharSequence testStr)
是否包含特定字符,忽略大小写,如果给定两个参数都为
null,返回true |
static boolean |
containsOnly(CharSequence text,
char... testChars)
检查指定字符串中是否只包含给定的字符
|
static int |
count(CharSequence content,
char charForSearch)
统计指定内容中包含指定字符的数量
|
static int |
count(CharSequence content,
CharSequence strForSearch)
统计指定内容中包含指定字符串的数量
参数为
null 或者 "" 返回 0. |
static String[] |
cut(CharSequence text,
int partLength)
将字符串切分为N等份
|
static String |
emptyIfNull(CharSequence text)
当给定字符串为null时,转换为Empty
|
static String |
emptyToDefault(CharSequence text,
String defaultStr)
如果字符串是
null或者"",则返回指定默认字符串,否则返回字符串本身。 |
static String |
emptyToNull(CharSequence text)
当给定字符串为空字符串时,转换为
null |
static boolean |
endsWithAny(CharSequence text,
CharSequence... word)
检查CharSequence是否以提供的大小写敏感的后缀结尾.
|
static boolean |
endWith(CharSequence text,
char c)
字符串是否以给定字符结尾
|
static boolean |
endWith(CharSequence text,
CharSequence suffix)
是否以指定字符串结尾
|
static boolean |
endWith(CharSequence text,
CharSequence suffix,
boolean isIgnoreCase)
是否以指定字符串结尾
如果给定的字符串和开头字符串都为null则返回true,否则任意一个值为null返回false
|
static boolean |
endWithAny(CharSequence text,
CharSequence... suffixes)
给定字符串是否以任何一个字符串结尾
给定字符串和数组为空都返回false
|
static boolean |
endWithAnyIgnoreCase(CharSequence text,
CharSequence... suffixes)
给定字符串是否以任何一个字符串结尾(忽略大小写)
给定字符串和数组为空都返回false
|
static boolean |
endWithIgnoreCase(CharSequence text,
CharSequence suffix)
是否以指定字符串结尾,忽略大小写
|
static boolean |
equals(char c1,
char c2,
boolean ignoreCase)
比较两个字符是否相同
|
static boolean |
equals(CharSequence stra,
CharSequence strb)
比较两个字符串(大小写敏感)
|
static boolean |
equals(CharSequence stra,
CharSequence strb,
boolean ignoreCase)
比较两个字符串是否相等
stra和strb都为
null
忽略大小写使用String.equalsIgnoreCase(String)判断相等
不忽略大小写使用String.contentEquals(CharSequence)判断相等
|
static boolean |
equalsAny(CharSequence str1,
boolean ignoreCase,
CharSequence... texts)
给定字符串是否与提供的中任一字符串相同,相同则返回
true,没有相同的返回false
如果参与比对的字符串列表为空,返回false |
static boolean |
equalsAny(CharSequence str1,
CharSequence... texts)
给定字符串是否与提供的中任一字符串相同,相同则返回
true,没有相同的返回false
如果参与比对的字符串列表为空,返回false |
static boolean |
equalsAnyIgnoreCase(CharSequence stra,
CharSequence... strb)
给定字符串是否与提供的中任一字符串相同(忽略大小写),相同则返回
true,没有相同的返回false
如果参与比对的字符串列表为空,返回false |
static boolean |
equalsCharAt(CharSequence text,
int position,
char c)
字符串指定位置的字符是否与给定字符相同
如果字符串为null,返回false
如果给定的位置大于字符串长度,返回false
如果给定的位置小于0,返回false
|
static boolean |
equalsIgnoreCase(CharSequence stra,
CharSequence strb)
比较两个字符串(大小写不敏感)
|
static String |
filter(CharSequence text,
Filter<Character> filter)
过滤字符串
|
<T extends CharSequence> |
firstNonBlank(T... texts)
返回第一个非blank 元素
|
<T extends CharSequence> |
firstNonEmpty(T... texts)
返回第一个非empty元素
|
<T extends CharSequence> |
firstNonNull(T... texts)
返回第一个非
null元素 |
static String |
format(CharSequence template,
Map<?,?> args)
格式化文本
|
static String |
format(CharSequence template,
Map<?,?> map,
boolean ignoreNull)
格式化文本,使用 {varName} 占位
map = {a: "aValue", b: "bValue"} format("{a} and {b}", map) - aValue and bValue
|
static String |
format(CharSequence template,
Object... args)
格式化文本, {} 表示占位符
此方法只是简单将占位符 {} 按照顺序替换为参数
如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可
例:
通常使用: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 char[] |
getChars(byte[] bytes) |
static String |
getContainsAny(CharSequence text,
CharSequence... testStrs)
查找指定字符串是否包含指定字符串列表中的任意一个字符串,如果包含返回找到的第一个字符串
|
static String |
getContainsStrIgnoreCase(CharSequence text,
CharSequence... testStrs)
查找指定字符串是否包含指定字符串列表中的任意一个字符串,如果包含返回找到的第一个字符串
忽略大小写
|
static boolean |
hasBlank(CharSequence... texts)
指定字符串数组中,是否包含空字符串
如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true
例:
StringKit.hasBlank() // true
StringKit.hasBlank("", null, " ") // true
StringKit.hasBlank("123", " ") // true
StringKit.hasBlank("123", "abc") // false
注意:该方法与 isAllBlank(CharSequence...) 的区别在于:
hasBlank(CharSequence...) 等价于 isBlank(...) || isBlank(...) || ...
isAllBlank(CharSequence...) 等价于 isBlank(...) && isBlank(...) && ...
|
static boolean |
hasEmpty(CharSequence... texts)
是否包含空字符串
如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true
例:
StringKit.hasEmpty() // true
StringKit.hasEmpty("", null) // true
StringKit.hasEmpty("123", "") // true
StringKit.hasEmpty("123", "abc") // false
StringKit.hasEmpty(" ", "\t", "\n") // false
注意:该方法与 isAllEmpty(CharSequence...) 的区别在于:
hasEmpty(CharSequence...) 等价于 isEmpty(...) || isEmpty(...) || ...
isAllEmpty(CharSequence...) 等价于 isEmpty(...) && isEmpty(...) && ...
|
static String |
hide(CharSequence text,
int startInclude,
int endExclude)
替换指定字符串的指定区间内字符为"*"
|
static int |
indexOf(CharSequence text,
char searchChar)
指定范围内查找指定字符
|
static int |
indexOf(CharSequence text,
char searchChar,
int start)
指定范围内查找指定字符
|
static int |
indexOf(CharSequence text,
char searchChar,
int start,
int end)
指定范围内查找指定字符
|
static int |
indexOf(CharSequence text,
CharSequence word,
int from,
boolean ignoreCase)
指定范围内反向查找字符串
|
static int |
indexOfIgnoreCase(CharSequence text,
CharSequence word)
指定范围内查找字符串,忽略大小写
|
static int |
indexOfIgnoreCase(CharSequence text,
CharSequence word,
int from)
指定范围内查找字符串
|
static boolean |
isAllBlank(CharSequence... texts)
指定字符串数组中的元素,是否全部为空字符串
如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true
例:
StringKit.isAllBlank() // true
StringKit.isAllBlank("", null, " ") // true
StringKit.isAllBlank("123", " ") // false
StringKit.isAllBlank("123", "abc") // false
注意:该方法与 hasBlank(CharSequence...) 的区别在于:
hasBlank(CharSequence...) 等价于 isBlank(...) || isBlank(...) || ...
isAllBlank(CharSequence...) 等价于 isBlank(...) && isBlank(...) && ...
|
static boolean |
isAllCharMatch(CharSequence value,
Matcher<Character> matcher)
字符串的每一个字符是否都与定义的匹配器匹配
|
static boolean |
isAllEmpty(CharSequence... texts)
指定字符串数组中的元素,是否全部为空字符串
如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true
例:
StringKit.isAllEmpty() // true
StringKit.isAllEmpty("", null) // true
StringKit.isAllEmpty("123", "") // false
StringKit.isAllEmpty("123", "abc") // false
StringKit.isAllEmpty(" ", "\t", "\n") // false
注意:该方法与 hasEmpty(CharSequence...) 的区别在于:
hasEmpty(CharSequence...) 等价于 isEmpty(...) || isEmpty(...) || ...
isAllEmpty(CharSequence...) 等价于 isEmpty(...) && isEmpty(...) && ...
|
static boolean |
isAllNotBlank(CharSequence... args)
是否存都不为
null或空对象或空白符的对象,通过hasBlank(CharSequence...) 判断元素 |
static boolean |
isAllNotEmpty(CharSequence... args)
指定字符串数组中的元素,是否都不为空字符串
如果指定的字符串数组的长度不为 0,或者所有元素都不是空字符串,则返回 true
例:
StringKit.isAllNotEmpty() // false
StringKit.isAllNotEmpty("", null) // false
StringKit.isAllNotEmpty("123", "") // false
StringKit.isAllNotEmpty("123", "abc") // true
StringKit.isAllNotEmpty(" ", "\t", "\n") // true
注意:该方法与 isAllEmpty(CharSequence...) 的区别在于:
isAllEmpty(CharSequence...) 等价于 isEmpty(...) && isEmpty(...) && ...
isAllNotEmpty(CharSequence...) 等价于 !isEmpty(...) && !isEmpty(...) && ...
|
static boolean |
isAnyBlank(CharSequence... texts)
检查任何一个字符序列是否为空(""),或为空,或仅为空白
|
static boolean |
isAscii(char ch)
是否为ASCII字符,ASCII字符位于0~127之间
|
static boolean |
isAsciiControl(char ch)
是否为ASCII控制符(不可见字符),控制符位于0~31和127
|
static boolean |
isAsciiPrintable(char ch)
是否为可见ASCII字符,可见字符位于32~126之间
|
static boolean |
isBlank(CharSequence text)
字符串是否为空白,空白的定义如下:
null
空字符串:""
空格、全角空格、制表符、换行符,等不可见字符
例:
StringKit.isBlank(null) // true
StringKit.isBlank("") // true
StringKit.isBlank(" \t\n") // true
StringKit.isBlank("abc") // false
注意:该方法与 isEmpty(CharSequence) 的区别是:
该方法会校验空白字符,且性能相对于 isEmpty(CharSequence) 略慢
建议:
该方法建议仅对于客户端(或第三方接口)传入的参数使用该方法。
需要同时校验多个字符串时,建议采用 hasBlank(CharSequence...) 或 isAllBlank(CharSequence...)
|
static boolean |
isBlankChar(char c)
是否空白符
空白符包括空格、制表符、全角空格和不间断空格
|
static boolean |
isBlankChar(int c)
是否空白符
空白符包括空格、制表符、全角空格和不间断空格
|
static boolean |
isBlankOrUndefined(CharSequence text)
检查字符串是否为null、空白串、“null”、“undefined”
|
static boolean |
isChar(Object value)
给定对象对应的类是否为字符类,字符类包括:
|
static boolean |
isCharClass(Class<?> clazz)
给定类名是否为字符类,字符类包括:
|
static boolean |
isCharEquals(CharSequence str)
检查给定字符串的所有字符是否都一样
|
static boolean |
isEmoji(char c)
判断是否为emoji表情符
|
static boolean |
isEmpty(CharSequence text)
字符串是否为空,空的定义如下:
null
空字符串:""
例:
StringKit.isEmpty(null) // true
StringKit.isEmpty("") // true
StringKit.isEmpty(" \t\n") // false
StringKit.isEmpty("abc") // false
注意:该方法与 isBlank(CharSequence) 的区别是:该方法不校验空白字符
建议:
该方法建议用于工具类或任何可以预期的方法参数的校验中
需要同时校验多个字符串时,建议采用 hasEmpty(CharSequence...) 或 isAllEmpty(CharSequence...)
|
static boolean |
isEmptyOrUndefined(CharSequence text)
检查字符串是否为null、“”、“null”、“undefined”
|
static boolean |
isFileSeparator(char c)
是否为Windows或者Linux(Unix)文件分隔符
Windows平台下分隔符为\,Linux(Unix)为/
|
static boolean |
isHexChar(char c)
是否为16进制规范的字符,判断是否为如下字符
|
static boolean |
isLetter(char ch)
判断是否为字母(包括大写字母和小写字母)
字母包括A~Z和a~z
|
static boolean |
isLetterLower(char ch)
检查字符是否为小写字母,小写字母指a~z
|
static boolean |
isLetterOrNumber(char ch)
是否为字母或数字,包括A~Z、a~z、0~9
|
static boolean |
isLetterUpper(char ch)
判断是否为大写字母,大写字母包括A~Z
|
static boolean |
isLowerCase(CharSequence text)
给定字符串中的字母是否全部为小写,判断依据如下:
|
static boolean |
isNoneBlank(CharSequence... texts)
检查是否没有字符序列为空("")、空字符或仅为空格
|
static boolean |
isNotBlank(CharSequence text)
字符串是否为非空白,非空白的定义如下:
不为
null
不为空字符串:""
不为空格、全角空格、制表符、换行符,等不可见字符
例:
StringKit.isNotBlank(null) // false
StringKit.isNotBlank("") // false
StringKit.isNotBlank(" \t\n") // false
StringKit.isNotBlank("abc") // true
注意:该方法与 isNotEmpty(CharSequence) 的区别是:
该方法会校验空白字符,且性能相对于 isNotEmpty(CharSequence) 略慢
建议:仅对于客户端(或第三方接口)传入的参数使用该方法 |
static boolean |
isNotEmpty(CharSequence text)
字符串是否为非空白,非空白的定义如下:
不为
null
不为空字符串:""
例:
StringKit.isNotEmpty(null) // false
StringKit.isNotEmpty("") // false
StringKit.isNotEmpty(" \t\n") // true
StringKit.isNotEmpty("abc") // true
注意:该方法与 isNotBlank(CharSequence) 的区别是:该方法不校验空白字符
建议:该方法建议用于工具类或任何可以预期的方法参数的校验中 |
static boolean |
isNullOrUndefined(CharSequence text)
检查字符串是否为null、“null”、“undefined”
|
static boolean |
isNumber(char ch)
检查是否为数字字符,数字字符指0~9
|
static boolean |
isSubEquals(CharSequence str1,
int start1,
CharSequence str2,
int start2,
int length,
boolean ignoreCase)
截取两个字符串的不同部分(长度一致),判断截取的子串是否相同
任意一个字符串为null返回false
|
static boolean |
isSurround(CharSequence text,
char prefix,
char suffix)
给定字符串是否被字符包围
|
static boolean |
isSurround(CharSequence text,
CharSequence prefix,
CharSequence suffix)
给定字符串是否被字符包围
|
static boolean |
isUpperCase(CharSequence text)
给定字符串中的字母是否全部为大写,判断依据如下:
|
static boolean |
isWrap(CharSequence text,
char wrapper)
指定字符串是否被同一字符包装(前后都有这些字符串)
|
static boolean |
isWrap(CharSequence text,
char prefixChar,
char suffixChar)
指定字符串是否被包装
|
static boolean |
isWrap(CharSequence text,
String wrapper)
指定字符串是否被同一字符包装(前后都有这些字符串)
|
static boolean |
isWrap(CharSequence text,
String prefix,
String suffix)
指定字符串是否被包装
|
static int |
lastIndexOf(CharSequence text,
CharSequence word,
int from,
boolean ignoreCase)
指定范围内查找字符串
|
static int |
lastIndexOfIgnoreCase(CharSequence text,
CharSequence word)
指定范围内查找字符串,忽略大小写
|
static int |
lastIndexOfIgnoreCase(CharSequence text,
CharSequence word,
int from)
指定范围内查找字符串,忽略大小写
|
static int |
length(CharSequence cs)
获取字符串的长度,如果为null返回0
|
static String |
lowerFirst(CharSequence text)
小写首字母
例如:text = Name, return name
|
static String |
maxLength(CharSequence string,
int length)
限制字符串长度,如果超过指定长度,截取指定长度并在末尾加"..."
|
static String |
normalize(CharSequence str)
对字符串归一化处理,如 "Á" 可以使用 "u00C1"或 "u0041u0301"表示,实际测试中两个字符串并不equals
因此使用此方法归一为一种表示形式,默认按照W3C通常建议的,在NFC中交换文本。
|
static String |
nullToDefault(CharSequence text,
String defaultStr)
如果字符串是
null,则返回指定默认字符串,否则返回字符串本身。 |
static String |
nullToEmpty(CharSequence text)
当给定字符串为null时,转换为Empty
|
static int |
ordinalIndexOf(CharSequence text,
CharSequence word,
int ordinal)
返回字符串 word 在字符串 text 中第 ordinal 次出现的位置
如果 text=null 或 word=null 或 ordinal小于等于0 则返回-1
|
static String |
padAfter(CharSequence text,
int minLength,
char padChar)
补充字符串以满足最小长度
|
static String |
padAfter(CharSequence text,
int minLength,
CharSequence padStr)
补充字符串以满足最小长度
|
static String |
padPre(CharSequence text,
int minLength,
char padChar)
补充字符串以满足最小长度
|
static String |
padPre(CharSequence text,
int minLength,
CharSequence padStr)
补充字符串以满足最小长度
|
static String |
prependIfMissing(String text,
CharSequence prefix,
CharSequence... prefixes)
如果字符串还没有以任何前缀开始,则将前缀添加到字符串的开头.
|
static String |
prependIfMissingIgnoreCase(String text,
CharSequence prefix,
CharSequence... prefixes)
如果字符串尚未开始,则将前缀添加到字符串的开头,不区分大小写,并使用任何前缀.
|
static String |
removeAll(CharSequence text,
char... chars)
去除字符串中指定的多个字符,如有多个则全部去除
|
static String |
removeAll(CharSequence text,
CharSequence strToRemove)
移除字符串中所有给定字符串
例:removeAll("aa-bb-cc-dd", "-") - aabbccdd
|
static String |
removeAny(CharSequence text,
CharSequence... strsToRemove)
移除字符串中所有给定字符串,当某个字符串出现多次,则全部移除
例:removeAny("aa-bb-cc-dd", "a", "b") - --cc-dd
|
static String |
removePreAndLowerFirst(CharSequence text,
CharSequence prefix)
去掉首部指定长度的字符串并将剩余字符串首字母小写
例如:text=setName, prefix=set = return name
|
static String |
removePreAndLowerFirst(CharSequence text,
int preLength)
去掉首部指定长度的字符串并将剩余字符串首字母小写
例如:text=setName, preLength=3 = return name
|
static String |
removePrefix(CharSequence text,
CharSequence prefix)
去掉指定前缀
|
static String |
removePrefixIgnoreCase(CharSequence text,
CharSequence prefix)
忽略大小写去掉指定前缀
|
static String |
removeSuffix(CharSequence text,
CharSequence suffix)
去掉指定后缀
|
static String |
repeat(char c,
int count)
重复某个字符
|
static String |
repeat(CharSequence text,
int count)
重复某个字符串
|
static String |
repeatAndJoin(CharSequence text,
int count,
CharSequence delimiter)
重复某个字符串并通过分界符连接
|
static String |
repeatByLength(CharSequence text,
int padLen)
重复某个字符串到指定长度
|
static String |
replace(CharSequence text)
替换字符串中的空格、回车、换行符、制表符
|
static String |
replace(CharSequence text,
CharSequence word,
CharSequence replacement)
替换字符串中的指定字符串
|
static String |
replace(CharSequence text,
CharSequence word,
CharSequence replacement,
boolean ignoreCase)
替换字符串中的指定字符串
|
static String |
replace(CharSequence text,
int fromIndex,
CharSequence word,
CharSequence replacement,
boolean ignoreCase)
替换字符串中的指定字符串
|
static String |
replace(CharSequence text,
int startInclude,
int endExclude,
char replacedChar)
替换指定字符串的指定区间内字符为固定字符
|
static String |
replace(CharSequence text,
int startInclude,
int endExclude,
CharSequence replacedStr)
替换指定字符串的指定区间内字符为指定字符串,字符串只重复一次
此方法使用 CharSequence.codePoints()完成拆分替换 |
static String |
replace(CharSequence text,
Pattern pattern,
Func1<Matcher,String> replaceFun)
替换所有正则匹配的文本,并使用自定义函数决定如何替换
replaceFun可以通过
Matcher提取出匹配到的内容的不同部分,然后经过重新处理、组装变成新的内容放回原位。
replace(this.content, "(\\d+)", parameters -> "-" + parameters.group(1) + "-")
// 结果为:"ZZZaaabbbccc中文-1234-" |
static String |
replace(CharSequence text,
String regex,
Func1<Matcher,String> replaceFun)
替换所有正则匹配的文本,并使用自定义函数决定如何替换
|
static String |
replaceChars(CharSequence text,
char[] chars,
CharSequence replacedStr)
替换字符字符数组中所有的字符为replacedStr
|
static String |
replaceChars(CharSequence text,
String chars,
CharSequence replacedStr)
替换字符字符数组中所有的字符为replacedStr
提供的chars为所有需要被替换的字符,例如:"\r\n",则"\r"和"\n"都会被替换,哪怕他们单独存在
|
static String |
replaceIgnoreCase(CharSequence text,
CharSequence word,
CharSequence replacement)
替换字符串中的指定字符串,忽略大小写
|
static String |
reverse(String text)
反转字符串
例如:abcd = dcba
|
static List<String> |
split(CharSequence text,
char separator)
切分字符串
a#b#c =》 [a,b,c]
a##b#c =》 [a,"",b,c]
|
static List<String> |
split(CharSequence text,
char separator,
boolean isTrim,
boolean ignoreEmpty)
切分字符串,不限制分片数量
|
static List<String> |
split(CharSequence text,
char separator,
int limit)
切分字符串,不去除切分后每个元素两边的空白符,不去除空白项
|
static List<String> |
split(CharSequence text,
char separator,
int limit,
boolean isTrim,
boolean ignoreEmpty)
切分字符串
|
static <R> List<R> |
split(CharSequence text,
char separator,
int limit,
boolean ignoreEmpty,
Function<String,R> mapping)
切分字符串
|
static List<String> |
split(CharSequence text,
CharSequence separator)
切分字符串,如果分隔符不存在则返回原字符串
|
static List<String> |
split(CharSequence text,
CharSequence separator,
boolean isTrim,
boolean ignoreEmpty)
切分字符串
|
static List<String> |
split(CharSequence text,
CharSequence separator,
int limit,
boolean isTrim,
boolean ignoreEmpty)
切分字符串
|
static String[] |
split(CharSequence text,
int len)
根据给定长度,将给定字符串截取为多个部分
|
static String[] |
splitToArray(CharSequence text,
char separator)
切分字符串
|
static String[] |
splitToArray(CharSequence text,
char separator,
int limit)
切分字符串
|
static String[] |
splitToArray(CharSequence text,
CharSequence separator)
切分字符串,如果分隔符不存在则返回原字符串
|
static int[] |
splitToInt(CharSequence text,
char separator)
切分字符串为int数组
|
static int[] |
splitToInt(CharSequence text,
CharSequence separator)
切分字符串为int数组
|
static long[] |
splitToLong(CharSequence text,
char separator)
切分字符串为long数组
|
static long[] |
splitToLong(CharSequence text,
CharSequence separator)
切分字符串为long数组
|
static List<String> |
splitTrim(CharSequence text,
char separator)
切分字符串,去除切分后每个元素两边的空白符,去除空白项
|
static List<String> |
splitTrim(CharSequence text,
char separator,
int limit)
切分字符串,去除切分后每个元素两边的空白符,去除空白项
|
static List<String> |
splitTrim(CharSequence text,
CharSequence separator)
切分字符串,去除切分后每个元素两边的空白符,去除空白项
|
static List<String> |
splitTrim(CharSequence text,
CharSequence separator,
int limit)
切分字符串,去除切分后每个元素两边的空白符,去除空白项
|
static boolean |
startWith(CharSequence text,
char c)
字符串是否以给定字符开始
|
static boolean |
startWith(CharSequence text,
CharSequence prefix)
是否以指定字符串开头
|
static boolean |
startWith(CharSequence text,
CharSequence prefix,
boolean ignoreCase)
是否以指定字符串开头
如果给定的字符串和开头字符串都为null则返回true,否则任意一个值为null返回false
|
static boolean |
startWith(CharSequence text,
CharSequence prefix,
boolean ignoreCase,
boolean ignoreEquals)
是否以指定字符串开头
如果给定的字符串和开头字符串都为null则返回true,否则任意一个值为null返回false
|
static boolean |
startWithAny(CharSequence text,
CharSequence... prefixes)
给定字符串是否以任何一个字符串开始
给定字符串和数组为空都返回false
|
static boolean |
startWithChinese(CharSequence text)
字符串是否以(中文汉字)开始
|
static boolean |
startWithGeneral(CharSequence text)
字符串是否以(英文字母 、数字和下划线)开始
|
static boolean |
startWithIgnoreCase(CharSequence text,
CharSequence prefix)
是否以指定字符串开头,忽略大小写
|
static boolean |
startWithIgnoreEquals(CharSequence text,
CharSequence prefix)
是否以指定字符串开头,忽略相等字符串的情况
|
static boolean |
startWithNumber(CharSequence text)
字符串是否以(数字)开始
|
static boolean |
startWithWord(CharSequence text)
字符串是否以(字母)开始
|
static String |
strip(CharSequence text,
CharSequence prefixOrSuffix)
去除两边的指定字符串
|
static String |
strip(CharSequence text,
CharSequence prefix,
CharSequence suffix)
去除两边的指定字符串
|
static String |
stripIgnoreCase(CharSequence text,
CharSequence prefixOrSuffix)
去除两边的指定字符串,忽略大小写
|
static String |
stripIgnoreCase(CharSequence text,
CharSequence prefix,
CharSequence suffix)
去除两边的指定字符串,忽略大小写
|
static String |
sub(CharSequence text,
int fromIndex,
int toIndex)
改进JDK subString
index从0开始计算,最后一个字符为-1
如果from和to位置一样,返回 ""
如果from或to为负数,则按照length从后向前数位置,如果绝对值大于字符串长度,则from归到0,to归到length
如果经过修正的index中from大于to,则互换
abcdefgh 2 3 = c
abcdefgh 2 -3 = cde
|
static String |
subAfter(CharSequence string,
char separator,
boolean isLastSeparator)
截取分隔字符串之后的字符串,不包括分隔字符串
如果给定的字符串为空串(null或""),返回原字符串
如果分隔字符串为空串(null或""),则返回空串,如果分隔字符串未找到,返回空串,举例如下:
|
static String |
subAfter(CharSequence string,
CharSequence separator,
boolean isLastSeparator)
截取分隔字符串之后的字符串,不包括分隔字符串
如果给定的字符串为空串(null或""),返回原字符串
如果分隔字符串为空串(null或""),则返回空串,如果分隔字符串未找到,返回空串,举例如下:
|
static String |
subBefore(CharSequence string,
char separator,
boolean isLastSeparator)
截取分隔字符串之前的字符串,不包括分隔字符串
如果给定的字符串为空串(null或"")或者分隔字符串为null,返回原字符串
如果分隔字符串未找到,返回原字符串,举例如下:
|
static String |
subBefore(CharSequence string,
CharSequence separator,
boolean isLastSeparator)
截取分隔字符串之前的字符串,不包括分隔字符串
如果给定的字符串为空串(null或"")或者分隔字符串为null,返回原字符串
如果分隔字符串为空串"",则返回空串,如果分隔字符串未找到,返回原字符串,举例如下:
|
static String |
subBetween(CharSequence text,
CharSequence beforeAndAfter)
截取指定字符串中间部分,不包括标识字符串
|
static String |
subBetween(CharSequence text,
CharSequence before,
CharSequence after)
截取指定字符串中间部分,不包括标识字符串
|
static String |
subBetween(String text,
String before,
String after)
截取指定字符串中间部分,不包括标识字符串
|
static String[] |
subBetweenAll(CharSequence text,
CharSequence prefixAndSuffix)
截取指定字符串多段中间部分,不包括标识字符串
|
static String[] |
subBetweenAll(CharSequence text,
CharSequence prefix,
CharSequence suffix)
截取指定字符串多段中间部分,不包括标识字符串
|
static String |
subByLength(CharSequence text,
int length)
切割指定长度的后部分的字符串
|
static String |
subCodePoint(CharSequence text,
int fromIndex,
int toIndex)
通过CodePoint截取字符串,可以截断Emoji
|
static String |
subPre(CharSequence string,
int toIndex)
切割指定位置之前部分的字符串
|
static String |
subPreGbk(CharSequence text,
int len,
boolean halfUp)
截取部分字符串,这里一个汉字的长度认为是2
可以自定义halfUp,如len为10,如果截取后最后一个字符是半个字符,
true表示保留,则长度是11,否则长度9 |
static String |
subPreGbk(CharSequence text,
int len,
CharSequence suffix)
截取部分字符串,这里一个汉字的长度认为是2
|
static String |
subSuf(CharSequence string,
int fromIndex)
切割指定位置之后部分的字符串
|
static String |
toCamelCase(CharSequence text)
将下划线方式命名的字符串转换为驼峰式
如果转换前的下划线大写方式命名的字符串为空,则返回空字符串
例如:hello_world = helloWorld
|
static String |
toCamelCase(CharSequence name,
char symbol)
将连接符方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串
例如:hello_world = helloWorld; hello-world = helloWorld
|
static char |
toCloseByNumber(int number)
封闭式字符,英文:Enclosed Alphanumerics
将[1-20]数字转换为带圈的字符:
|
static char |
toCloseChar(char c)
将字母、数字转换为带圈的字符:
|
static String |
toString(char c)
字符转为字符串
如果为ASCII字符,使用缓存
|
static String |
toString(CharSequence cs)
CharSequence 转为字符串,null安全 |
static String |
toSymbolCase(CharSequence text,
char symbol)
将驼峰式命名的字符串转换为使用符号连接方式
如果转换前的驼峰式命名的字符串为空,则返回空字符串
|
static String |
toUnderlineCase(CharSequence camelCaseStr)
将驼峰式命名的字符串转换为下划线方式
如果转换前的驼峰式命名的字符串为空,则返回空字符串
例如:HelloWorld= hello_world
|
static String |
trim(CharSequence text)
字符串去空格
|
static String |
trim(CharSequence text,
int mode)
除去字符串头尾部的空白符,如果字符串是null,依然返回null
|
static String |
trim(CharSequence text,
int mode,
Predicate<Character> predicate)
按照断言,除去字符串头尾部的断言为真的字符,如果字符串是
null,依然返回null。 |
static String |
trimToNull(CharSequence text)
删除字符串两端的空白字符(char <= 32),如果字符串在修剪后为空("")
或者如果字符串为
null,则返回null |
static String |
unWrap(CharSequence text,
char prefixAndSuffix)
去掉字符包装,如果未被包装则返回原字符串
|
static String |
unWrap(CharSequence text,
char prefix,
char suffix)
去掉字符包装,如果未被包装则返回原字符串
|
static String |
unWrap(CharSequence text,
String prefix,
String suffix)
去掉字符包装,如果未被包装则返回原字符串
|
static String |
upperFirst(CharSequence text)
大写首字母
例如:text = name, return Name
|
static String |
upperFirstAndAddPre(CharSequence text,
String preString)
原字符串首字母大写并在其首部添加指定字符串
例如:text=name, preString=get = return getName
|
static String |
wrap(CharSequence text,
CharSequence prefixAndSuffix)
包装指定字符串
当前缀和后缀一致时使用此方法
|
static String |
wrap(CharSequence text,
CharSequence prefix,
CharSequence suffix)
包装指定字符串
|
static String[] |
wrapAll(CharSequence prefixAndSuffix,
CharSequence... texts)
包装多个字符串
|
static String[] |
wrapAll(CharSequence prefix,
CharSequence suffix,
CharSequence... texts)
包装多个字符串
|
static String[] |
wrapAllIfMissing(CharSequence prefixAndSuffix,
CharSequence... texts)
包装多个字符串,如果已经包装,则不再包装
|
static String[] |
wrapAllIfMissing(CharSequence prefix,
CharSequence suffix,
CharSequence... texts)
包装多个字符串,如果已经包装,则不再包装
|
static String |
wrapIfMissing(CharSequence text,
CharSequence prefix,
CharSequence suffix)
包装指定字符串,如果前缀或后缀已经包含对应的字符串,则不再包装
|
public static boolean isAscii(char ch)
CharKit.isAscii('a') = true
CharKit.isAscii('A') = true
CharKit.isAscii('3') = true
CharKit.isAscii('-') = true
CharKit.isAscii('\n') = true
CharKit.isAscii('©') = false
ch - 被检查的字符处public static boolean isAsciiPrintable(char ch)
CharKit.isAsciiPrintable('a') = true
CharKit.isAsciiPrintable('A') = true
CharKit.isAsciiPrintable('3') = true
CharKit.isAsciiPrintable('-') = true
CharKit.isAsciiPrintable('\n') = false
CharKit.isAsciiPrintable('©') = false
ch - 被检查的字符处public static boolean isAsciiControl(char ch)
CharKit.isAsciiControl('a') = false
CharKit.isAsciiControl('A') = false
CharKit.isAsciiControl('3') = false
CharKit.isAsciiControl('-') = false
CharKit.isAsciiControl('\n') = true
CharKit.isAsciiControl('©') = false
ch - 被检查的字符public static boolean isLetter(char ch)
CharKit.isLetter('a') = true
CharKit.isLetter('A') = true
CharKit.isLetter('3') = false
CharKit.isLetter('-') = false
CharKit.isLetter('\n') = false
CharKit.isLetter('©') = false
ch - 被检查的字符public static boolean isLetterUpper(char ch)
CharKit.isLetterUpper('a') = false
CharKit.isLetterUpper('A') = true
CharKit.isLetterUpper('3') = false
CharKit.isLetterUpper('-') = false
CharKit.isLetterUpper('\n') = false
CharKit.isLetterUpper('©') = false
ch - 被检查的字符public static boolean isLetterLower(char ch)
CharKit.isLetterLower('a') = true
CharKit.isLetterLower('A') = false
CharKit.isLetterLower('3') = false
CharKit.isLetterLower('-') = false
CharKit.isLetterLower('\n') = false
CharKit.isLetterLower('©') = false
ch - 被检查的字符public static boolean isNumber(char ch)
CharKit.isNumber('a') = false
CharKit.isNumber('A') = false
CharKit.isNumber('3') = true
CharKit.isNumber('-') = false
CharKit.isNumber('\n') = false
CharKit.isNumber('©') = false
ch - 被检查的字符public static boolean isHexChar(char c)
1. 0~9 2. a~f 4. A~F
c - 字符public static boolean isLetterOrNumber(char ch)
CharKit.isLetterOrNumber('a') = true
CharKit.isLetterOrNumber('A') = true
CharKit.isLetterOrNumber('3') = true
CharKit.isLetterOrNumber('-') = false
CharKit.isLetterOrNumber('\n') = false
CharKit.isLetterOrNumber('©') = false
ch - 被检查的字符public static boolean isCharClass(Class<?> clazz)
Character.class char.class
clazz - 被检查的类public static boolean isChar(Object value)
Character.class char.class
value - 被检查的对象public static boolean isBlankChar(char c)
c - 字符Character.isWhitespace(int),
Character.isSpaceChar(int)public static boolean isBlankChar(int c)
c - 字符Character.isWhitespace(int),
Character.isSpaceChar(int)public static boolean isBlank(CharSequence text)
null""StringKit.isBlank(null) // trueStringKit.isBlank("") // trueStringKit.isBlank(" \t\n") // trueStringKit.isBlank("abc") // falseisEmpty(CharSequence) 的区别是:
该方法会校验空白字符,且性能相对于 isEmpty(CharSequence) 略慢
建议:
hasBlank(CharSequence...) 或 isAllBlank(CharSequence...)text - 被检测的字符串isEmpty(CharSequence)public static boolean isNotBlank(CharSequence text)
null""StringKit.isNotBlank(null) // falseStringKit.isNotBlank("") // falseStringKit.isNotBlank(" \t\n") // falseStringKit.isNotBlank("abc") // trueisNotEmpty(CharSequence) 的区别是:
该方法会校验空白字符,且性能相对于 isNotEmpty(CharSequence) 略慢
建议:仅对于客户端(或第三方接口)传入的参数使用该方法text - 被检测的字符串isBlank(CharSequence)public static boolean isNoneBlank(CharSequence... texts)
StringKit.isNoneBlank(null) = false
StringKit.isNoneBlank(null, "foo") = false
StringKit.isNoneBlank(null, null) = false
StringKit.isNoneBlank("", "bar") = false
StringKit.isNoneBlank("bob", "") = false
StringKit.isNoneBlank(" bob ", null) = false
StringKit.isNoneBlank(" ", "bar") = false
StringKit.isNoneBlank(new String[] {}) = true
StringKit.isNoneBlank(new String[]{""}) = false
StringKit.isNoneBlank("foo", "bar") = true
texts - 要检查的字符串可以为null或空public static boolean isAnyBlank(CharSequence... texts)
StringKit.isAnyBlank((String) null) = true
StringKit.isAnyBlank((String[]) null) = false
StringKit.isAnyBlank(null, "foo") = true
StringKit.isAnyBlank(null, null) = true
StringKit.isAnyBlank("", "bar") = true
StringKit.isAnyBlank("bob", "") = true
StringKit.isAnyBlank(" bob ", null) = true
StringKit.isAnyBlank(" ", "bar") = true
StringKit.isAnyBlank(new String[] {}) = false
StringKit.isAnyBlank(new String[]{""}) = true
StringKit.isAnyBlank("foo", "bar") = false
texts - 要检查的字符序列可以为空或空public static boolean isAllBlank(CharSequence... texts)
StringKit.isAllBlank() // trueStringKit.isAllBlank("", null, " ") // trueStringKit.isAllBlank("123", " ") // falseStringKit.isAllBlank("123", "abc") // falsehasBlank(CharSequence...) 的区别在于:
hasBlank(CharSequence...) 等价于 isBlank(...) || isBlank(...) || ...isBlank(...) && isBlank(...) && ...texts - 字符串列表public static boolean isEmpty(CharSequence text)
null""StringKit.isEmpty(null) // trueStringKit.isEmpty("") // trueStringKit.isEmpty(" \t\n") // falseStringKit.isEmpty("abc") // falseisBlank(CharSequence) 的区别是:该方法不校验空白字符
建议:
hasEmpty(CharSequence...) 或 isAllEmpty(CharSequence...)text - 被检测的字符串isBlank(CharSequence)public static boolean isNotEmpty(CharSequence text)
null""StringKit.isNotEmpty(null) // falseStringKit.isNotEmpty("") // falseStringKit.isNotEmpty(" \t\n") // trueStringKit.isNotEmpty("abc") // trueisNotBlank(CharSequence) 的区别是:该方法不校验空白字符
建议:该方法建议用于工具类或任何可以预期的方法参数的校验中text - 被检测的字符串isEmpty(CharSequence)public static boolean isAllEmpty(CharSequence... texts)
StringKit.isAllEmpty() // trueStringKit.isAllEmpty("", null) // trueStringKit.isAllEmpty("123", "") // falseStringKit.isAllEmpty("123", "abc") // falseStringKit.isAllEmpty(" ", "\t", "\n") // falsehasEmpty(CharSequence...) 的区别在于:
hasEmpty(CharSequence...) 等价于 isEmpty(...) || isEmpty(...) || ...isEmpty(...) && isEmpty(...) && ...texts - 字符串列表public static boolean isAllNotEmpty(CharSequence... args)
StringKit.isAllNotEmpty() // falseStringKit.isAllNotEmpty("", null) // falseStringKit.isAllNotEmpty("123", "") // falseStringKit.isAllNotEmpty("123", "abc") // trueStringKit.isAllNotEmpty(" ", "\t", "\n") // trueisAllEmpty(CharSequence...) 的区别在于:
isAllEmpty(CharSequence...) 等价于 isEmpty(...) && isEmpty(...) && ...!isEmpty(...) && !isEmpty(...) && ...args - 字符串数组public static boolean isAllNotBlank(CharSequence... args)
null或空对象或空白符的对象,通过hasBlank(CharSequence...) 判断元素args - 被检查的对象,一个或者多个public static boolean isNullOrUndefined(CharSequence text)
text - 被检查的字符串public static boolean isEmptyOrUndefined(CharSequence text)
text - 被检查的字符串public static boolean isBlankOrUndefined(CharSequence text)
text - 被检查的字符串public static boolean hasBlank(CharSequence... texts)
StringKit.hasBlank() // trueStringKit.hasBlank("", null, " ") // trueStringKit.hasBlank("123", " ") // trueStringKit.hasBlank("123", "abc") // falseisAllBlank(CharSequence...) 的区别在于:
isBlank(...) || isBlank(...) || ...isAllBlank(CharSequence...) 等价于 isBlank(...) && isBlank(...) && ...texts - 字符串列表public static boolean isAllCharMatch(CharSequence value, Matcher<Character> matcher)
value - 字符串matcher - 匹配器public static String emptyIfNull(CharSequence text)
text - 被检查的字符串nullToEmpty(CharSequence)public static String emptyToNull(CharSequence text)
nulltext - 被转换的字符串public static boolean hasEmpty(CharSequence... texts)
StringKit.hasEmpty() // trueStringKit.hasEmpty("", null) // trueStringKit.hasEmpty("123", "") // trueStringKit.hasEmpty("123", "abc") // falseStringKit.hasEmpty(" ", "\t", "\n") // falseisAllEmpty(CharSequence...) 的区别在于:
isEmpty(...) || isEmpty(...) || ...isAllEmpty(CharSequence...) 等价于 isEmpty(...) && isEmpty(...) && ...texts - 字符串列表public static boolean isEmoji(char c)
c - 字符public static boolean equals(char c1,
char c2,
boolean ignoreCase)
c1 - 字符1c2 - 字符2ignoreCase - 是否忽略大小写public static int count(CharSequence content, CharSequence strForSearch)
null 或者 "" 返回 0.
count(null, *) = 0
count("", *) = 0
count("abba", null) = 0
count("abba", "") = 0
count("abba", "a") = 2
count("abba", "ab") = 1
count("abba", "xxx") = 0
content - 被查找的字符串strForSearch - 需要查找的字符串public static int count(CharSequence content, char charForSearch)
content - 内容charForSearch - 被统计的字符public static boolean isFileSeparator(char c)
c - 字符public static int compare(char x,
char y)
char值进行数值比较x - chary - char
如果x == y返回值0;
如果x < y值小于0;和
如果x > ypublic static char[] getChars(byte[] bytes)
public static char byteToChar(byte[] b)
b - 字节信息public static char toCloseChar(char c)
'1' -》 '①'
'A' -》 'Ⓐ'
'a' -》 'ⓐ'
获取带圈数字 /封闭式字母数字 ,从1-20,超过1-20报错
0 1 2 3 4 5 6 7 8 9 A B C D E F
U+246x ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯
U+247x ⑰ ⑱ ⑲ ⑳ ⑴ ⑵ ⑶ ⑷ ⑸ ⑹ ⑺ ⑻ ⑼ ⑽ ⑾ ⑿
U+248x ⒀ ⒁ ⒂ ⒃ ⒄ ⒅ ⒆ ⒇ ⒈ ⒉ ⒊ ⒋ ⒌ ⒍ ⒎ ⒏
U+249x ⒐ ⒑ ⒒ ⒓ ⒔ ⒕ ⒖ ⒗ ⒘ ⒙ ⒚ ⒛ ⒜ ⒝ ⒞ ⒟
U+24Ax ⒠ ⒡ ⒢ ⒣ ⒤ ⒥ ⒦ ⒧ ⒨ ⒩ ⒪ ⒫ ⒬ ⒭ ⒮ ⒯
U+24Bx ⒰ ⒱ ⒲ ⒳ ⒴ ⒵ Ⓐ Ⓑ Ⓒ Ⓓ Ⓔ Ⓕ Ⓖ Ⓗ Ⓘ Ⓙ
U+24Cx Ⓚ Ⓛ Ⓜ Ⓝ Ⓞ Ⓟ Ⓠ Ⓡ Ⓢ Ⓣ Ⓤ Ⓥ Ⓦ Ⓧ Ⓨ Ⓩ
U+24Dx ⓐ ⓑ ⓒ ⓓ ⓔ ⓕ ⓖ ⓗ ⓘ ⓙ ⓚ ⓛ ⓜ ⓝ ⓞ ⓟ
U+24Ex ⓠ ⓡ ⓢ ⓣ ⓤ ⓥ ⓦ ⓧ ⓨ ⓩ ⓪ ⓫ ⓬ ⓭ ⓮ ⓯
U+24Fx ⓰ ⓱ ⓲ ⓳ ⓴ ⓵ ⓶ ⓷ ⓸ ⓹ ⓺ ⓻ ⓼ ⓽ ⓾ ⓿c - 被转换的字符,如果字符不支持转换,返回原字符public static char toCloseByNumber(int number)
1 -》 '①'
12 -》 '⑫'
20 -》 '⑳'
number - 被转换的数字public static boolean startWithNumber(CharSequence text)
text - 字符串public static boolean startWithGeneral(CharSequence text)
text - 字符串public static boolean startWithWord(CharSequence text)
text - 字符串public static boolean startWithChinese(CharSequence text)
text - 字符串public static boolean isCharEquals(CharSequence str)
str - 字符出啊public static String normalize(CharSequence str)
str - 归一化的字符串Normalizer.normalize(CharSequence, Normalizer.Form)public static String trim(CharSequence text)
text - 原始字符串public static String trim(CharSequence text, int mode)
text - 要处理的字符串mode - -1去除开始位置,0全部去除, 1去除结束位置public static String trim(CharSequence text, int mode, Predicate<Character> predicate)
null,依然返回null。text - 要处理的字符串mode - -1表示trimStart,0表示trim全部, 1表示trimEndpredicate - 断言是否过掉字符,返回true表述过滤掉,false表示不过滤null,则返回nullpublic static String trimToNull(CharSequence text)
null,则返回null
StringKit.trimToNull(null) = null
StringKit.trimToNull("") = null
StringKit.trimToNull(" ") = null
StringKit.trimToNull("abc") = "abc"
StringKit.trimToEmpty(" abc ") = "abc"
text - 字符串public static String removePreAndLowerFirst(CharSequence text, int preLength)
text - 被处理的字符串preLength - 去掉的长度public static String removePreAndLowerFirst(CharSequence text, CharSequence prefix)
text - 被处理的字符串prefix - 前缀public static String removePrefix(CharSequence text, CharSequence prefix)
text - 字符串prefix - 前缀public static String removePrefixIgnoreCase(CharSequence text, CharSequence prefix)
text - 字符串prefix - 前缀public static String removeSuffix(CharSequence text, CharSequence suffix)
text - 字符串suffix - 后缀public static String upperFirstAndAddPre(CharSequence text, String preString)
text - 被处理的字符串preString - 添加的首部public static String upperFirst(CharSequence text)
text - 字符串public static String lowerFirst(CharSequence text)
text - 字符串public static String toUnderlineCase(CharSequence camelCaseStr)
camelCaseStr - 转换前的驼峰式命名的字符串public static String toSymbolCase(CharSequence text, char symbol)
text - 转换前的驼峰式命名的字符串,也可以为符号连接形式symbol - 连接符public static String toCamelCase(CharSequence text)
text - 转换前的下划线大写方式命名的字符串public static String toCamelCase(CharSequence name, char symbol)
name - 转换前的下划线大写方式命名的字符串symbol - 连接符NamingCase.toCamelCase(CharSequence, char)public static String removeAll(CharSequence text, CharSequence strToRemove)
text - 字符串strToRemove - 被移除的字符串public static String removeAll(CharSequence text, char... chars)
text - 字符串chars - 字符列表public static String removeAny(CharSequence text, CharSequence... strsToRemove)
text - 字符串strsToRemove - 被移除的字符串public static String format(CharSequence template, Map<?,?> args)
template - 文本模板,被替换的部分用 {key} 表示args - 参数值对public static String format(CharSequence template, Object... args)
template - 文本模板,被替换的部分用 {} 表示,如果模板为null,返回"null"args - 参数值public static String format(CharSequence template, Map<?,?> map, boolean ignoreNull)
template - 文本模板,被替换的部分用 {key} 表示map - 参数值对ignoreNull - 是否忽略 null 值,忽略则 null 值对应的变量不被替换,否则替换为""public static String sub(CharSequence text, int fromIndex, int toIndex)
text - StringfromIndex - 开始的index(包括)toIndex - 结束的index(不包括)public static String subPre(CharSequence string, int toIndex)
string - 字符串toIndex - 切割到的位置(不包括)public static String subPreGbk(CharSequence text, int len, CharSequence suffix)
text - 字符串len - bytes切割到的位置(包含)suffix - 切割后加上后缀public static String subPreGbk(CharSequence text, int len, boolean halfUp)
true表示保留,则长度是11,否则长度9text - 字符串len - bytes切割到的位置(包含)halfUp - 遇到截取一半的GBK字符,是否保留。public static String subSuf(CharSequence string, int fromIndex)
string - 字符串fromIndex - 切割开始的位置(包括)public static String subBefore(CharSequence string, CharSequence separator, boolean isLastSeparator)
StringKit.subBefore(null, *) = null
StringKit.subBefore("", *) = ""
StringKit.subBefore("abc", "a") = ""
StringKit.subBefore("abcba", "b") = "a"
StringKit.subBefore("abc", "c") = "ab"
StringKit.subBefore("abc", "d") = "abc"
StringKit.subBefore("abc", "") = ""
StringKit.subBefore("abc", null) = "abc"
string - 被查找的字符串separator - 分隔字符串(不包括)isLastSeparator - 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个public static String subBefore(CharSequence string, char separator, boolean isLastSeparator)
StringKit.subBefore(null, *) = null
StringKit.subBefore("", *) = ""
StringKit.subBefore("abc", 'a') = ""
StringKit.subBefore("abcba", 'b') = "a"
StringKit.subBefore("abc", 'c') = "ab"
StringKit.subBefore("abc", 'd') = "abc"
string - 被查找的字符串separator - 分隔字符串(不包括)isLastSeparator - 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个public static String subAfter(CharSequence string, CharSequence separator, boolean isLastSeparator)
StringKit.subAfter(null, *) = null
StringKit.subAfter("", *) = ""
StringKit.subAfter(*, null) = ""
StringKit.subAfter("abc", "a") = "bc"
StringKit.subAfter("abcba", "b") = "cba"
StringKit.subAfter("abc", "c") = ""
StringKit.subAfter("abc", "d") = ""
StringKit.subAfter("abc", "") = "abc"
string - 被查找的字符串separator - 分隔字符串(不包括)isLastSeparator - 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个public static String subAfter(CharSequence string, char separator, boolean isLastSeparator)
StringKit.subAfter(null, *) = null
StringKit.subAfter("", *) = ""
StringKit.subAfter("abc", 'a') = "bc"
StringKit.subAfter("abcba", 'b') = "cba"
StringKit.subAfter("abc", 'c') = ""
StringKit.subAfter("abc", 'd') = ""
string - 被查找的字符串separator - 分隔字符串(不包括)isLastSeparator - 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个public static String subBetween(CharSequence text, CharSequence before, CharSequence after)
text - 被切割的字符串before - 截取开始的字符串标识after - 截取到的字符串标识public static String subBetween(String text, String before, String after)
StringKit.subBetween("wx[b]yz", "[", "]") = "b"
StringKit.subBetween(null, *, *) = null
StringKit.subBetween(*, null, *) = null
StringKit.subBetween(*, *, null) = null
StringKit.subBetween("", "", "") = ""
StringKit.subBetween("", "", "]") = null
StringKit.subBetween("", "[", "]") = null
StringKit.subBetween("yabcz", "", "") = ""
StringKit.subBetween("yabcz", "y", "z") = "abc"
StringKit.subBetween("yabczyabcz", "y", "z") = "abc"
text - 被切割的字符串before - 截取开始的字符串标识after - 截取到的字符串标识public static String subBetween(CharSequence text, CharSequence beforeAndAfter)
StringKit.subBetween(null, *) = null
StringKit.subBetween("", "") = ""
StringKit.subBetween("", "tag") = null
StringKit.subBetween("tagabctag", null) = null
StringKit.subBetween("tagabctag", "") = ""
StringKit.subBetween("tagabctag", "tag") = "abc"
text - 被切割的字符串beforeAndAfter - 截取开始和结束的字符串标识public static String[] subBetweenAll(CharSequence text, CharSequence prefix, CharSequence suffix)
StringKit.subBetweenAll("wx[b]y[z]", "[", "]") = ["b","z"]
StringKit.subBetweenAll(null, *, *) = []
StringKit.subBetweenAll(*, null, *) = []
StringKit.subBetweenAll(*, *, null) = []
StringKit.subBetweenAll("", "", "") = []
StringKit.subBetweenAll("", "", "]") = []
StringKit.subBetweenAll("", "[", "]") = []
StringKit.subBetweenAll("yabcz", "", "") = []
StringKit.subBetweenAll("yabcz", "y", "z") = ["abc"]
StringKit.subBetweenAll("yabczyabcz", "y", "z") = ["abc","abc"]
StringKit.subBetweenAll("[yabc[zy]abcz]", "[", "]"); = ["zy"]
text - 被切割的字符串prefix - 截取开始的字符串标识suffix - 截取到的字符串标识public static String[] subBetweenAll(CharSequence text, CharSequence prefixAndSuffix)
栗子:
StringKit.subBetweenAll(null, *) = []
StringKit.subBetweenAll(*, null) = []
StringKit.subBetweenAll(*, *) = []
StringKit.subBetweenAll("", "") = []
StringKit.subBetweenAll("", "#") = []
StringKit.subBetweenAll("hello", "") = []
StringKit.subBetweenAll("#hello#", "#") = ["hello"]
StringKit.subBetweenAll("#hello# #world#!", "#") = ["hello", "world"]
StringKit.subBetweenAll("#hello# world#!", "#"); = ["hello"]
text - 被切割的字符串prefixAndSuffix - 截取开始和结束的字符串标识public static String subByLength(CharSequence text, int length)
StringKit.subSufByLength("abcde", 3) = "cde"
StringKit.subSufByLength("abcde", 0) = ""
StringKit.subSufByLength("abcde", -5) = ""
StringKit.subSufByLength("abcde", -1) = ""
StringKit.subSufByLength("abcde", 5) = "abcde"
StringKit.subSufByLength("abcde", 10) = "abcde"
StringKit.subSufByLength(null, 3) = null
text - 字符串length - 切割长度public static boolean equals(CharSequence stra, CharSequence strb)
equals(null, null) = true
equals(null, "abc") = false
equals("abc", null) = false
equals("abc", "abc") = true
equals("abc", "ABC") = false
stra - 要比较的字符串strb - 要比较的字符串null,则返回truepublic static boolean equals(CharSequence stra, CharSequence strb, boolean ignoreCase)
nullString.equalsIgnoreCase(String)判断相等String.contentEquals(CharSequence)判断相等stra - 要比较的字符串strb - 要比较的字符串ignoreCase - 是否忽略大小写null,则返回truepublic static boolean equalsIgnoreCase(CharSequence stra, CharSequence strb)
equalsIgnoreCase(null, null) = true
equalsIgnoreCase(null, "abc") = false
equalsIgnoreCase("abc", null) = false
equalsIgnoreCase("abc", "abc") = true
equalsIgnoreCase("abc", "ABC") = true
stra - 要比较的字符串strb - 要比较的字符串null,则返回truepublic static boolean equalsAnyIgnoreCase(CharSequence stra, CharSequence... strb)
true,没有相同的返回false
如果参与比对的字符串列表为空,返回falsestra - 给定需要检查的字符串strb - 需要参与比对的字符串列表public static boolean equalsAny(CharSequence str1, CharSequence... texts)
true,没有相同的返回false
如果参与比对的字符串列表为空,返回falsestr1 - 给定需要检查的字符串texts - 需要参与比对的字符串列表public static boolean equalsAny(CharSequence str1, boolean ignoreCase, CharSequence... texts)
true,没有相同的返回false
如果参与比对的字符串列表为空,返回falsestr1 - 给定需要检查的字符串ignoreCase - 是否忽略大小写texts - 需要参与比对的字符串列表public static int indexOf(CharSequence text, char searchChar)
text - 字符串searchChar - 被查找的字符public static int indexOf(CharSequence text, char searchChar, int start)
text - 字符串searchChar - 被查找的字符start - 起始位置,如果小于0,从0开始查找public static int indexOf(CharSequence text, char searchChar, int start, int end)
text - 字符串searchChar - 被查找的字符start - 起始位置,如果小于0,从0开始查找end - 终止位置,如果超过text.length()则默认查找到字符串末尾public static int indexOfIgnoreCase(CharSequence text, CharSequence word)
StringKit.indexOfIgnoreCase(null, *, *) = -1
StringKit.indexOfIgnoreCase(*, null, *) = -1
StringKit.indexOfIgnoreCase("", "", 0) = 0
StringKit.indexOfIgnoreCase("aabaabaa", "A", 0) = 0
StringKit.indexOfIgnoreCase("aabaabaa", "B", 0) = 2
StringKit.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1
StringKit.indexOfIgnoreCase("aabaabaa", "B", 3) = 5
StringKit.indexOfIgnoreCase("aabaabaa", "B", 9) = -1
StringKit.indexOfIgnoreCase("aabaabaa", "B", -1) = 2
StringKit.indexOfIgnoreCase("aabaabaa", "", 2) = 2
StringKit.indexOfIgnoreCase("abc", "", 9) = -1
text - 字符串word - 需要查找位置的字符串public static int indexOfIgnoreCase(CharSequence text, CharSequence word, int from)
StringKit.indexOfIgnoreCase(null, *, *) = -1
StringKit.indexOfIgnoreCase(*, null, *) = -1
StringKit.indexOfIgnoreCase("", "", 0) = 0
StringKit.indexOfIgnoreCase("aabaabaa", "A", 0) = 0
StringKit.indexOfIgnoreCase("aabaabaa", "B", 0) = 2
StringKit.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1
StringKit.indexOfIgnoreCase("aabaabaa", "B", 3) = 5
StringKit.indexOfIgnoreCase("aabaabaa", "B", 9) = -1
StringKit.indexOfIgnoreCase("aabaabaa", "B", -1) = 2
StringKit.indexOfIgnoreCase("aabaabaa", "", 2) = 2
StringKit.indexOfIgnoreCase("abc", "", 9) = -1
text - 字符串word - 需要查找位置的字符串from - 起始位置public static int indexOf(CharSequence text, CharSequence word, int from, boolean ignoreCase)
text - 字符串,空则返回-1word - 需要查找位置的字符串,空则返回-1from - 起始位置(包含)ignoreCase - 是否忽略大小写public static int lastIndexOfIgnoreCase(CharSequence text, CharSequence word)
text - 字符串word - 需要查找位置的字符串public static int lastIndexOfIgnoreCase(CharSequence text, CharSequence word, int from)
text - 字符串word - 需要查找位置的字符串from - 起始位置,从后往前计数public static int lastIndexOf(CharSequence text, CharSequence word, int from, boolean ignoreCase)
text - 字符串word - 需要查找位置的字符串from - 起始位置,从后往前计数ignoreCase - 是否忽略大小写public static long[] splitToLong(CharSequence text, char separator)
text - 被切分的字符串separator - 分隔符public static long[] splitToLong(CharSequence text, CharSequence separator)
text - 被切分的字符串separator - 分隔符字符串public static int[] splitToInt(CharSequence text, char separator)
text - 被切分的字符串separator - 分隔符public static int[] splitToInt(CharSequence text, CharSequence separator)
text - 被切分的字符串separator - 分隔符字符串public static String[] splitToArray(CharSequence text, CharSequence separator)
text - 被切分的字符串separator - 分隔符public static String[] splitToArray(CharSequence text, char separator)
text - 被切分的字符串separator - 分隔符字符public static String[] splitToArray(CharSequence text, char separator, int limit)
text - 被切分的字符串separator - 分隔符字符limit - 限制分片数public static List<String> split(CharSequence text, char separator)
text - 被切分的字符串separator - 分隔符字符public static List<String> splitTrim(CharSequence text, char separator)
text - 被切分的字符串separator - 分隔符字符public static List<String> splitTrim(CharSequence text, CharSequence separator)
text - 被切分的字符串separator - 分隔符字符public static List<String> splitTrim(CharSequence text, char separator, int limit)
text - 被切分的字符串separator - 分隔符字符limit - 限制分片数,-1不限制public static List<String> splitTrim(CharSequence text, CharSequence separator, int limit)
text - 被切分的字符串separator - 分隔符字符limit - 限制分片数,-1不限制public static String[] split(CharSequence text, int len)
text - 字符串len - 每一个小节的长度TextSplitter.splitByLength(String, int)public static List<String> split(CharSequence text, CharSequence separator)
text - 被切分的字符串separator - 分隔符public static List<String> split(CharSequence text, char separator, int limit)
text - 被切分的字符串separator - 分隔符字符limit - 限制分片数,-1不限制public static List<String> split(CharSequence text, char separator, boolean isTrim, boolean ignoreEmpty)
text - 被切分的字符串separator - 分隔符字符isTrim - 是否去除切分字符串后每个元素两边的空格ignoreEmpty - 是否忽略空串public static List<String> split(CharSequence text, CharSequence separator, boolean isTrim, boolean ignoreEmpty)
text - 被切分的字符串separator - 分隔符字符isTrim - 是否去除切分字符串后每个元素两边的空格ignoreEmpty - 是否忽略空串public static List<String> split(CharSequence text, char separator, int limit, boolean isTrim, boolean ignoreEmpty)
text - 被切分的字符串separator - 分隔符字符limit - 限制分片数,-1不限制isTrim - 是否去除切分字符串后每个元素两边的空格ignoreEmpty - 是否忽略空串public static List<String> split(CharSequence text, CharSequence separator, int limit, boolean isTrim, boolean ignoreEmpty)
text - 被切分的字符串separator - 分隔符字符limit - 限制分片数,-1不限制isTrim - 是否去除切分字符串后每个元素两边的空格ignoreEmpty - 是否忽略空串public static <R> List<R> split(CharSequence text, char separator, int limit, boolean ignoreEmpty, Function<String,R> mapping)
R - 切分后元素类型text - 被切分的字符串separator - 分隔符字符limit - 限制分片数,-1不限制ignoreEmpty - 是否忽略空串mapping - 切分后的字符串元素的转换方法public static String subCodePoint(CharSequence text, int fromIndex, int toIndex)
text - stringfromIndex - 开始的index(包括)toIndex - 结束的index(不包括)public static String nullToEmpty(CharSequence text)
text - 被转换的字符串public static String nullToDefault(CharSequence text, String defaultStr)
null,则返回指定默认字符串,否则返回字符串本身。
nullToDefault(null, "default") = "default"
nullToDefault("", "default") = ""
nullToDefault(" ", "default") = " "
nullToDefault("bat", "default") = "bat"
text - 要转换的字符串defaultStr - 默认字符串public static String emptyToDefault(CharSequence text, String defaultStr)
null或者"",则返回指定默认字符串,否则返回字符串本身。
emptyToDefault(null, "default") = "default"
emptyToDefault("", "default") = "default"
emptyToDefault(" ", "default") = " "
emptyToDefault("bat", "default") = "bat"
text - 要转换的字符串defaultStr - 默认字符串public static String blankToDefault(CharSequence text, String defaultStr)
null或者""或者空白,则返回指定默认字符串,否则返回字符串本身。
emptyToDefault(null, "default") = "default"
emptyToDefault("", "default") = "default"
emptyToDefault(" ", "default") = "default"
emptyToDefault("bat", "default") = "bat"
text - 要转换的字符串defaultStr - 默认字符串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 repeat(char c, int count)
c - 被重复的字符count - 重复的数目,如果小于等于0则返回""public static String repeat(CharSequence text, int count)
text - 被重复的字符count - 重复的数目public static String repeatByLength(CharSequence text, int padLen)
text - 被重复的字符padLen - 指定长度public static String repeatAndJoin(CharSequence text, int count, CharSequence delimiter)
StringKit.repeatAndJoin("?", 5, ",") = "?,?,?,?,?"
StringKit.repeatAndJoin("?", 0, ",") = ""
StringKit.repeatAndJoin("?", 5, null) = "?????"
text - 被重复的字符串count - 数量delimiter - 分界符public static String reverse(String text)
text - 被反转的字符串public static byte[] bytes(CharSequence text)
text - 字符串public static byte[] bytes(CharSequence text, String charset)
text - 字符串charset - 字符集,如果此字段为空,则解码的结果取决于平台public static byte[] bytes(CharSequence text, Charset charset)
text - 字符串charset - 字符集,如果此字段为空,则解码的结果取决于平台public static String replaceIgnoreCase(CharSequence text, CharSequence word, CharSequence replacement)
text - 字符串word - 被查找的字符串replacement - 被替换的字符串public static String replace(CharSequence text)
text - 字符串信息public static String replace(CharSequence text, CharSequence word, CharSequence replacement)
text - 字符串word - 被查找的字符串replacement - 被替换的字符串public static String replace(CharSequence text, CharSequence word, CharSequence replacement, boolean ignoreCase)
text - 字符串word - 被查找的字符串replacement - 被替换的字符串ignoreCase - 是否忽略大小写public static String replace(CharSequence text, int fromIndex, CharSequence word, CharSequence replacement, boolean ignoreCase)
text - 字符串fromIndex - 开始位置(包括)word - 被查找的字符串replacement - 被替换的字符串ignoreCase - 是否忽略大小写public static String replace(CharSequence text, String regex, Func1<Matcher,String> replaceFun)
text - 要替换的字符串regex - 用于匹配的正则式replaceFun - 决定如何替换的函数public static String replace(CharSequence text, int startInclude, int endExclude, CharSequence replacedStr)
CharSequence.codePoints()完成拆分替换text - 字符串startInclude - 开始位置(包含)endExclude - 结束位置(不包含)replacedStr - 被替换的字符串public static String replace(CharSequence text, Pattern pattern, Func1<Matcher,String> replaceFun)
Matcher提取出匹配到的内容的不同部分,然后经过重新处理、组装变成新的内容放回原位。
replace(this.content, "(\\d+)", parameters -> "-" + parameters.group(1) + "-")
// 结果为:"ZZZaaabbbccc中文-1234-"
text - 要替换的字符串pattern - 用于匹配的正则式replaceFun - 决定如何替换的函数public static String replace(CharSequence text, int startInclude, int endExclude, char replacedChar)
text - 字符串startInclude - 开始位置(包含)endExclude - 结束位置(不包含)replacedChar - 被替换的字符public static String hide(CharSequence text, int startInclude, int endExclude)
text - 字符串startInclude - 开始位置(包含)endExclude - 结束位置(不包含)public static String replaceChars(CharSequence text, String chars, CharSequence replacedStr)
text - 被检查的字符串chars - 需要替换的字符列表,用一个字符串表示这个字符列表replacedStr - 替换成的字符串public static String replaceChars(CharSequence text, char[] chars, CharSequence replacedStr)
text - 被检查的字符串chars - 需要替换的字符列表replacedStr - 替换成的字符串public static String cleanBlank(CharSequence text)
text - 被清理的字符串public static String wrap(CharSequence text, CharSequence prefixAndSuffix)
text - 被包装的字符串prefixAndSuffix - 前缀和后缀public static String wrap(CharSequence text, CharSequence prefix, CharSequence suffix)
text - 被包装的字符串prefix - 前缀suffix - 后缀public static String[] wrapAll(CharSequence prefixAndSuffix, CharSequence... texts)
prefixAndSuffix - 前缀和后缀texts - 多个字符串public static String[] wrapAll(CharSequence prefix, CharSequence suffix, CharSequence... texts)
prefix - 前缀suffix - 后缀texts - 多个字符串public static String unWrap(CharSequence text, String prefix, String suffix)
text - 字符串prefix - 前置字符串suffix - 后置字符串public static String unWrap(CharSequence text, char prefix, char suffix)
text - 字符串prefix - 前置字符suffix - 后置字符public static String unWrap(CharSequence text, char prefixAndSuffix)
text - 字符串prefixAndSuffix - 前置和后置字符public static boolean isWrap(CharSequence text, String prefix, String suffix)
text - 字符串prefix - 前缀suffix - 后缀public static boolean isWrap(CharSequence text, String wrapper)
text - 字符串wrapper - 包装字符串public static boolean isWrap(CharSequence text, char wrapper)
text - 字符串wrapper - 包装字符public static boolean isWrap(CharSequence text, char prefixChar, char suffixChar)
text - 字符串prefixChar - 前缀suffixChar - 后缀public static String wrapIfMissing(CharSequence text, CharSequence prefix, CharSequence suffix)
text - 被包装的字符串prefix - 前缀suffix - 后缀public static String[] wrapAllIfMissing(CharSequence prefixAndSuffix, CharSequence... texts)
prefixAndSuffix - 前缀和后缀texts - 多个字符串public static String[] wrapAllIfMissing(CharSequence prefix, CharSequence suffix, CharSequence... texts)
prefix - 前缀suffix - 后缀texts - 多个字符串public static boolean startWith(CharSequence text, char c)
text - 字符串c - 字符public static boolean startWith(CharSequence text, CharSequence prefix, boolean ignoreCase)
text - 被监测字符串prefix - 开头字符串ignoreCase - 是否忽略大小写public static boolean startWith(CharSequence text, CharSequence prefix, boolean ignoreCase, boolean ignoreEquals)
text - 被监测字符串prefix - 开头字符串ignoreCase - 是否忽略大小写ignoreEquals - 是否忽略字符串相等的情况public static boolean startWith(CharSequence text, CharSequence prefix)
text - 被监测字符串prefix - 开头字符串public static boolean startWithIgnoreEquals(CharSequence text, CharSequence prefix)
text - 被监测字符串prefix - 开头字符串public static boolean startWithAny(CharSequence text, CharSequence... prefixes)
text - 给定字符串prefixes - 需要检测的开始字符串public static boolean startWithIgnoreCase(CharSequence text, CharSequence prefix)
text - 被监测字符串prefix - 开头字符串public static boolean endWith(CharSequence text, char c)
text - 字符串c - 字符public static boolean endWith(CharSequence text, CharSequence suffix, boolean isIgnoreCase)
text - 被监测字符串suffix - 结尾字符串isIgnoreCase - 是否忽略大小写public static boolean endWith(CharSequence text, CharSequence suffix)
text - 被监测字符串suffix - 结尾字符串public static boolean endWithAny(CharSequence text, CharSequence... suffixes)
text - 给定字符串suffixes - 需要检测的结尾字符串public static boolean endWithAnyIgnoreCase(CharSequence text, CharSequence... suffixes)
text - 给定字符串suffixes - 需要检测的结尾字符串public static boolean endWithIgnoreCase(CharSequence text, CharSequence suffix)
text - 被监测字符串suffix - 结尾字符串public static String strip(CharSequence text, CharSequence prefixOrSuffix)
text - 被处理的字符串prefixOrSuffix - 前缀或后缀public static String strip(CharSequence text, CharSequence prefix, CharSequence suffix)
text - 被处理的字符串prefix - 前缀suffix - 后缀public static String stripIgnoreCase(CharSequence text, CharSequence prefixOrSuffix)
text - 被处理的字符串prefixOrSuffix - 前缀或后缀public static String stripIgnoreCase(CharSequence text, CharSequence prefix, CharSequence suffix)
text - 被处理的字符串prefix - 前缀suffix - 后缀public static String addPrefixIfNot(CharSequence text, CharSequence prefix)
text - 字符串prefix - 前缀public static String addSuffixIfNot(CharSequence text, CharSequence suffix)
text - 字符串suffix - 后缀public static boolean contains(CharSequence text, char searchChar)
text - 字符串searchChar - 被查找的字符public static boolean contains(CharSequence text, CharSequence word)
text - 字符串word - 被查找的字符串public static boolean containsAny(CharSequence text, CharSequence... testStrs)
text - 指定字符串testStrs - 需要检查的字符串数组public static boolean containsAny(CharSequence text, char... testChars)
text - 指定字符串testChars - 需要检查的字符数组public static boolean containsOnly(CharSequence text, char... testChars)
text - 字符串testChars - 检查的字符public static boolean containsBlank(CharSequence text)
text - 字符串public static String getContainsAny(CharSequence text, CharSequence... testStrs)
text - 指定字符串testStrs - 需要检查的字符串数组public static boolean containsIgnoreCase(CharSequence text, CharSequence testStr)
null,返回truetext - 被检测字符串testStr - 被测试是否包含的字符串public static boolean containsAnyIgnoreCase(CharSequence text, CharSequence... testStrs)
text - 指定字符串testStrs - 需要检查的字符串数组public static String getContainsStrIgnoreCase(CharSequence text, CharSequence... testStrs)
text - 指定字符串testStrs - 需要检查的字符串数组public static boolean isSurround(CharSequence text, CharSequence prefix, CharSequence suffix)
text - 字符串prefix - 前缀suffix - 后缀public static boolean isSurround(CharSequence text, char prefix, char suffix)
text - 字符串prefix - 前缀suffix - 后缀public static boolean isUpperCase(CharSequence text)
1. 大写字母包括A-Z 2. 其它非字母的Unicode符都算作大写
text - 被检查的字符串public static boolean isLowerCase(CharSequence text)
1. 小写字母包括a-z 2. 其它非字母的Unicode符都算作小写
text - 被检查的字符串public static int byteLength(CharSequence cs, Charset charset)
cs - 字符串charset - 编码public static String[] cut(CharSequence text, int partLength)
text - 字符串partLength - 每等份的长度public static String brief(CharSequence text, int maxLength)
text - 字符串maxLength - 最大长度public static String appendIfMissing(String text, CharSequence suffix, CharSequence... suffixes)
StringKit.appendIfMissing(null, null) = null
StringKit.appendIfMissing("abc", null) = "abc"
StringKit.appendIfMissing("", "xyz") = "xyz"
StringKit.appendIfMissing("abc", "xyz") = "abcxyz"
StringKit.appendIfMissing("abcxyz", "xyz") = "abcxyz"
StringKit.appendIfMissing("abcXYZ", "xyz") = "abcXYZxyz"
With additional suffixes,
StringKit.appendIfMissing(null, null, null) = null
StringKit.appendIfMissing("abc", null, null) = "abc"
StringKit.appendIfMissing("", "xyz", null) = "xyz"
StringKit.appendIfMissing("abc", "xyz", new CharSequence[]{null}) = "abcxyz"
StringKit.appendIfMissing("abc", "xyz", "") = "abc"
StringKit.appendIfMissing("abc", "xyz", "mno") = "abcxyz"
StringKit.appendIfMissing("abcxyz", "xyz", "mno") = "abcxyz"
StringKit.appendIfMissing("abcmno", "xyz", "mno") = "abcmno"
StringKit.appendIfMissing("abcXYZ", "xyz", "mno") = "abcXYZxyz"
StringKit.appendIfMissing("abcMNO", "xyz", "mno") = "abcMNOxyz"
text - 字符串.suffix - 附加到字符串末尾的后缀.suffixes - 有效终止符的附加后缀(可选).public static String appendIfMissingIgnoreCase(String text, CharSequence suffix, CharSequence... suffixes)
StringKit.appendIfMissingIgnoreCase(null, null) = null
StringKit.appendIfMissingIgnoreCase("abc", null) = "abc"
StringKit.appendIfMissingIgnoreCase("", "xyz") = "xyz"
StringKit.appendIfMissingIgnoreCase("abc", "xyz") = "abcxyz"
StringKit.appendIfMissingIgnoreCase("abcxyz", "xyz") = "abcxyz"
StringKit.appendIfMissingIgnoreCase("abcXYZ", "xyz") = "abcXYZ"
With additional suffixes,
StringKit.appendIfMissingIgnoreCase(null, null, null) = null
StringKit.appendIfMissingIgnoreCase("abc", null, null) = "abc"
StringKit.appendIfMissingIgnoreCase("", "xyz", null) = "xyz"
StringKit.appendIfMissingIgnoreCase("abc", "xyz", new CharSequence[]{null}) = "abcxyz"
StringKit.appendIfMissingIgnoreCase("abc", "xyz", "") = "abc"
StringKit.appendIfMissingIgnoreCase("abc", "xyz", "mno") = "axyz"
StringKit.appendIfMissingIgnoreCase("abcxyz", "xyz", "mno") = "abcxyz"
StringKit.appendIfMissingIgnoreCase("abcmno", "xyz", "mno") = "abcmno"
StringKit.appendIfMissingIgnoreCase("abcXYZ", "xyz", "mno") = "abcXYZ"
StringKit.appendIfMissingIgnoreCase("abcMNO", "xyz", "mno") = "abcMNO"
text - 字符串.suffix - 附加到字符串末尾的后缀.suffixes - 有效终止符的附加后缀(可选).public static String prependIfMissing(String text, CharSequence prefix, CharSequence... prefixes)
StringKit.prependIfMissing(null, null) = null
StringKit.prependIfMissing("abc", null) = "abc"
StringKit.prependIfMissing("", "xyz") = "xyz"
StringKit.prependIfMissing("abc", "xyz") = "xyzabc"
StringKit.prependIfMissing("xyzabc", "xyz") = "xyzabc"
StringKit.prependIfMissing("XYZabc", "xyz") = "xyzXYZabc"
With additional prefixes,
StringKit.prependIfMissing(null, null, null) = null
StringKit.prependIfMissing("abc", null, null) = "abc"
StringKit.prependIfMissing("", "xyz", null) = "xyz"
StringKit.prependIfMissing("abc", "xyz", new CharSequence[]{null}) = "xyzabc"
StringKit.prependIfMissing("abc", "xyz", "") = "abc"
StringKit.prependIfMissing("abc", "xyz", "mno") = "xyzabc"
StringKit.prependIfMissing("xyzabc", "xyz", "mno") = "xyzabc"
StringKit.prependIfMissing("mnoabc", "xyz", "mno") = "mnoabc"
StringKit.prependIfMissing("XYZabc", "xyz", "mno") = "xyzXYZabc"
StringKit.prependIfMissing("MNOabc", "xyz", "mno") = "xyzMNOabc"
text - T字符串.prefix - 在字符串开始前的前缀.prefixes - 有效的附加前缀(可选).public static String prependIfMissingIgnoreCase(String text, CharSequence prefix, CharSequence... prefixes)
StringKit.prependIfMissingIgnoreCase(null, null) = null
StringKit.prependIfMissingIgnoreCase("abc", null) = "abc"
StringKit.prependIfMissingIgnoreCase("", "xyz") = "xyz"
StringKit.prependIfMissingIgnoreCase("abc", "xyz") = "xyzabc"
StringKit.prependIfMissingIgnoreCase("xyzabc", "xyz") = "xyzabc"
StringKit.prependIfMissingIgnoreCase("XYZabc", "xyz") = "XYZabc"
With additional prefixes,
StringKit.prependIfMissingIgnoreCase(null, null, null) = null
StringKit.prependIfMissingIgnoreCase("abc", null, null) = "abc"
StringKit.prependIfMissingIgnoreCase("", "xyz", null) = "xyz"
StringKit.prependIfMissingIgnoreCase("abc", "xyz", new CharSequence[]{null}) = "xyzabc"
StringKit.prependIfMissingIgnoreCase("abc", "xyz", "") = "abc"
StringKit.prependIfMissingIgnoreCase("abc", "xyz", "mno") = "xyzabc"
StringKit.prependIfMissingIgnoreCase("xyzabc", "xyz", "mno") = "xyzabc"
StringKit.prependIfMissingIgnoreCase("mnoabc", "xyz", "mno") = "mnoabc"
StringKit.prependIfMissingIgnoreCase("XYZabc", "xyz", "mno") = "XYZabc"
StringKit.prependIfMissingIgnoreCase("MNOabc", "xyz", "mno") = "MNOabc"
text - T字符串.prefix - 在字符串开始前的前缀.prefixes - 有效的附加前缀(可选).public static String maxLength(CharSequence string, int length)
string - 字符串length - 最大长度public static String center(CharSequence text, int size)
StringKit.center(null, *) = null
StringKit.center("", 4) = " "
StringKit.center("ab", -1) = "ab"
StringKit.center("ab", 4) = " ab "
StringKit.center("abcd", 2) = "abcd"
StringKit.center("a", 4) = " a "
text - 字符串size - 指定长度public static String center(CharSequence text, int size, char padChar)
StringKit.center(null, *, *) = null
StringKit.center("", 4, ' ') = " "
StringKit.center("ab", -1, ' ') = "ab"
StringKit.center("ab", 4, ' ') = " ab "
StringKit.center("abcd", 2, ' ') = "abcd"
StringKit.center("a", 4, ' ') = " a "
StringKit.center("a", 4, 'y') = "yayy"
StringKit.center("abc", 7, ' ') = " abc "
text - 字符串size - 指定长度padChar - 两边补充的字符public static String center(CharSequence text, int size, CharSequence padStr)
StringKit.center(null, *, *) = null
StringKit.center("", 4, " ") = " "
StringKit.center("ab", -1, " ") = "ab"
StringKit.center("ab", 4, " ") = " ab "
StringKit.center("abcd", 2, " ") = "abcd"
StringKit.center("a", 4, " ") = " a "
StringKit.center("a", 4, "yz") = "yayz"
StringKit.center("abc", 7, null) = " abc "
StringKit.center("abc", 7, "") = " abc "
text - 字符串size - 指定长度padStr - 两边补充的字符串public static String padPre(CharSequence text, int minLength, CharSequence padStr)
StringKit.padPre(null, *, *);//null
StringKit.padPre("1", 3, "ABC");//"AB1"
StringKit.padPre("123", 2, "ABC");//"12"
text - 字符串minLength - 最小长度padStr - 补充的字符public static String padPre(CharSequence text, int minLength, char padChar)
StringKit.padPre(null, *, *);//null
StringKit.padPre("1", 3, '0');//"001"
StringKit.padPre("123", 2, '0');//"12"
text - 字符串minLength - 最小长度padChar - 补充的字符public static String padAfter(CharSequence text, int minLength, char padChar)
StringKit.padAfter(null, *, *);//null
StringKit.padAfter("1", 3, '0');//"100"
StringKit.padAfter("123", 2, '0');//"23"
text - 字符串,如果为null,直接返回nullminLength - 最小长度padChar - 补充的字符public static String padAfter(CharSequence text, int minLength, CharSequence padStr)
StringKit.padAfter(null, *, *);//null
StringKit.padAfter("1", 3, "ABC");//"1AB"
StringKit.padAfter("123", 2, "ABC");//"23"
text - 字符串,如果为null,直接返回nullminLength - 最小长度padStr - 补充的字符public static boolean equalsCharAt(CharSequence text, int position, char c)
text - 字符串position - 位置c - 需要对比的字符public static String filter(CharSequence text, Filter<Character> filter)
text - 字符串filter - 过滤器public static StringBuilder builder(CharSequence... text)
text - 初始字符串列表public static int length(CharSequence cs)
cs - a 字符串public static int ordinalIndexOf(CharSequence text, CharSequence word, int ordinal)
StringKit.ordinalIndexOf(null, *, *) = -1
StringKit.ordinalIndexOf(*, null, *) = -1
StringKit.ordinalIndexOf("", "", *) = 0
StringKit.ordinalIndexOf("aabaabaa", "a", 1) = 0
StringKit.ordinalIndexOf("aabaabaa", "a", 2) = 1
StringKit.ordinalIndexOf("aabaabaa", "b", 1) = 2
StringKit.ordinalIndexOf("aabaabaa", "b", 2) = 5
StringKit.ordinalIndexOf("aabaabaa", "ab", 1) = 1
StringKit.ordinalIndexOf("aabaabaa", "ab", 2) = 4
StringKit.ordinalIndexOf("aabaabaa", "", 1) = 0
StringKit.ordinalIndexOf("aabaabaa", "", 2) = 0
text - 被检查的字符串,可以为nullword - 被查找的字符串,可以为nullordinal - 第几次出现的位置public static String toString(CharSequence cs)
CharSequence 转为字符串,null安全cs - CharSequencepublic static String toString(char c)
c - 字符public static boolean endsWithAny(CharSequence text, CharSequence... word)
StringKit.endsWithAny(null, null) = false
StringKit.endsWithAny(null, new String[] {"abc"}) = false
StringKit.endsWithAny("abcxyz", null) = false
StringKit.endsWithAny("abcxyz", new String[] {""}) = true
StringKit.endsWithAny("abcxyz", new String[] {"xyz"}) = true
StringKit.endsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = true
StringKit.endsWithAny("abcXYZ", "def", "XYZ") = true
StringKit.endsWithAny("abcXYZ", "def", "xyz") = false
text - 要检查的CharSequence可能为空word - 要查找的区分大小写的字符序列可以是空的,也可以包含nullsequence是null, 并且没有提供searchstring,
或者输入sequence以提供的区分大小写的searchstring结尾.public <T extends CharSequence> T firstNonNull(T... texts)
null元素T - 元素类型texts - 多个元素nullpublic <T extends CharSequence> T firstNonEmpty(T... texts)
T - 元素类型texts - 多个元素nullisNotEmpty(CharSequence)public <T extends CharSequence> T firstNonBlank(T... texts)
T - 元素类型texts - 多个元素nullisNotBlank(CharSequence)Copyright © 2022. All rights reserved.