public class UStringUtil extends Object
Modifier and Type | Field and Description |
---|---|
static String |
BACKSLASH |
static String |
BRACKET_END |
static String |
BRACKET_START |
static char |
C_BACKSLASH |
static char |
C_BRACKET_END |
static char |
C_BRACKET_START |
static char |
C_COLON |
static char |
C_COMMA |
static char |
C_CR |
static char |
C_DELIM_END |
static char |
C_DELIM_START |
static char |
C_DOT |
static char |
C_LF |
static char |
C_SLASH |
static char |
C_SPACE |
static char |
C_TAB |
static char |
C_UNDERLINE |
static String |
COLON |
static String |
COMMA |
static String |
CR |
static String |
CRLF |
static String |
DASHED |
static String |
DELIM_END |
static String |
DELIM_START |
static String |
DOT |
static String |
DOUBLE_DOT |
static String |
EMPTY |
static String |
EMPTY_JSON |
static String |
HTML_AMP |
static String |
HTML_APOS |
static String |
HTML_GT |
static String |
HTML_LT |
static String |
HTML_NBSP |
static String |
HTML_QUOTE |
static int |
INDEX_NOT_FOUND |
static String |
LF |
static String |
SLASH |
static String |
SPACE |
static String |
TAB |
static String |
UNDERLINE |
Constructor and Description |
---|
UStringUtil() |
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... suffixes)
如果给定字符串不是以给定的一个或多个字符串为结尾,则在尾部添加结尾字符串
|
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" 形式的字符串
|
static StringBuilder |
builder()
创建StringBuilder对象
|
static StringBuilder |
builder(CharSequence... strs)
创建StringBuilder对象
|
static StringBuilder |
builder(int capacity)
创建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)
居中字符串,两边补充指定字符串,如果指定长度小于字符串,则返回原字符串
|
static String |
center(CharSequence str,
int size,
char padChar)
居中字符串,两边补充指定字符串,如果指定长度小于字符串,则返回原字符串
|
static String |
center(CharSequence str,
int size,
CharSequence padStr)
居中字符串,两边补充指定字符串,如果指定长度小于字符串,则返回原字符串
|
static String |
cleanBlank(CharSequence str)
清理空白字符
|
static int |
compare(CharSequence str1,
CharSequence str2,
boolean nullIsLess)
比较两个字符串,用于排序
|
static int |
compareIgnoreCase(CharSequence str1,
CharSequence str2,
boolean nullIsLess)
比较两个字符串,用于排序,大小写不敏感
|
static int |
compareVersion(CharSequence version1,
CharSequence version2)
比较两个版本
null版本排在最小:既:
|
static String |
concat(boolean isNullToEmpty,
CharSequence... strs)
连接多个字符串为一个
|
static boolean |
contains(CharSequence str,
char searchChar)
指定字符是否在字符串中出现过
|
static boolean |
contains(CharSequence str,
CharSequence searchStr)
指定字符串是否在字符串中出现过
|
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)
检查指定字符串中是否只包含给定的字符
|
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 |
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 isIgnoreCase)
是否以指定字符串结尾
如果给定的字符串和开头字符串都为null则返回true,否则任意一个值为null返回false |
static boolean |
endWithAny(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)
比较两个字符串是否相等。
|
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 |
fill(String str,
char filledChar,
int len,
boolean isPre)
将已有字符串填充为规定长度,如果已有字符串超过这个长度则返回这个字符串
|
static String |
fillAfter(String str,
char filledChar,
int len)
将已有字符串填充为规定长度,如果已有字符串超过这个长度则返回这个字符串
字符填充于字符串后 |
static String |
fillBefore(String str,
char filledChar,
int len)
将已有字符串填充为规定长度,如果已有字符串超过这个长度则返回这个字符串
字符填充于字符串前 |
static String |
format(CharSequence template,
Map<?,?> map)
格式化文本,使用 {varName} 占位
map = {a: "aValue", b: "bValue"} format("{a} and {b}", map) ---=》 aValue and bValue |
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方法对应的标准属性名
例如:setName 返回 name |
static StringReader |
getReader(CharSequence str)
获得StringReader
|
static StringWriter |
getWriter()
获得StringWriter
|
static boolean |
hasBlank(CharSequence... strs)
是否包含空字符串
|
static boolean |
hasEmpty(CharSequence... strs)
是否包含空字符串
|
static String |
hide(CharSequence str,
int startInclude,
int endExclude)
替换指定字符串的指定区间内字符为"*"
|
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 str,
char searchChar,
int start,
int end)
指定范围内查找指定字符
|
static int |
indexOf(CharSequence str,
CharSequence searchStr,
int fromIndex,
boolean ignoreCase)
指定范围内反向查找字符串
|
static int |
indexOfIgnoreCase(CharSequence str,
CharSequence searchStr)
指定范围内查找字符串,忽略大小写
|
static int |
indexOfIgnoreCase(CharSequence str,
CharSequence searchStr,
int fromIndex)
指定范围内查找字符串
|
static boolean |
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)
是否存都不为
null 或空对象,通过hasEmpty(CharSequence...) 判断元素 |
static boolean |
isBlank(CharSequence str)
字符串是否为空白 空白的定义如下:
1、为null 2、为不可见字符(如空格) 3、"" |
static boolean |
isBlankIfStr(Object obj)
如果对象是字符串是否为空白,空白的定义如下:
1、为null 2、为不可见字符(如空格) 3、"" |
static boolean |
isBlankOrUndefined(CharSequence str)
检查字符串是否为null、空白串、“null”、“undefined”
|
static boolean |
isEmpty(CharSequence str)
字符串是否为空,空的定义如下:
1、为null 2、为"" |
static boolean |
isEmptyIfStr(Object obj)
如果对象是字符串是否为空串空的定义如下:
1、为null 2、为"" |
static boolean |
isEmptyOrUndefined(CharSequence str)
检查字符串是否为null、“”、“null”、“undefined”
|
static boolean |
isLowerCase(CharSequence str)
给定字符串中的字母是否全部为小写,判断依据如下:
|
static boolean |
isNotBlank(CharSequence str)
字符串是否为非空白 空白的定义如下:
1、不为null 2、不为不可见字符(如空格) 3、不为"" |
static boolean |
isNotEmpty(CharSequence str)
字符串是否为非空白 空白的定义如下:
1、不为null 2、不为"" |
static boolean |
isNullOrUndefined(CharSequence str)
检查字符串是否为null、“null”、“undefined”
|
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)
给定字符串中的字母是否全部为大写,判断依据如下:
|
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 String |
join(CharSequence conjunction,
Object... objs)
以 conjunction 为分隔符将多个对象转换为字符串
|
static int |
lastIndexOf(CharSequence str,
CharSequence searchStr,
int fromIndex,
boolean ignoreCase)
指定范围内查找字符串
|
static int |
lastIndexOfIgnoreCase(CharSequence str,
CharSequence searchStr)
指定范围内查找字符串,忽略大小写
|
static int |
lastIndexOfIgnoreCase(CharSequence str,
CharSequence searchStr,
int fromIndex)
指定范围内查找字符串,忽略大小写
|
static 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 |
nullToDefault(CharSequence str,
String defaultStr)
如果字符串是
null ,则返回指定默认字符串,否则返回字符串本身。 |
static String |
nullToEmpty(CharSequence str)
当给定字符串为null时,转换为Empty
|
static int |
ordinalIndexOf(String str,
String searchStr,
int ordinal)
返回字符串 searchStr 在字符串 str 中第 ordinal 次出现的位置。
如果 str等于null 或 searchStr等于null 或 ordinal小于等于0 则返回-1 此方法来自:Apache-Commons-Lang |
static String |
padAfter(CharSequence str,
int minLength,
char padChar)
补充字符串以满足最小长度
|
static String |
padAfter(CharSequence str,
int minLength,
CharSequence padStr)
补充字符串以满足最小长度
|
static String |
padEnd(CharSequence str,
int minLength,
char padChar)
Deprecated.
|
static String |
padPre(CharSequence str,
int minLength,
char padChar)
补充字符串以满足最小长度
|
static String |
padPre(CharSequence str,
int minLength,
CharSequence padStr)
补充字符串以满足最小长度
|
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)
去除所有换行符,包括:
|
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)
重复某个字符
|
static String |
repeat(CharSequence str,
int count)
重复某个字符串
|
static String |
repeatAndJoin(CharSequence str,
int count,
CharSequence conjunction)
重复某个字符串并通过分界符连接
|
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)
替换指定字符串的指定区间内字符为固定字符
|
static String |
replace(CharSequence str,
Pattern pattern,
Func1<Matcher,String> replaceFun)
替换所有正则匹配的文本,并使用自定义函数决定如何替换
|
static String |
replace(CharSequence str,
String regex,
Func1<Matcher,String> replaceFun)
替换所有正则匹配的文本,并使用自定义函数决定如何替换
|
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 |
replaceIgnoreCase(CharSequence str,
CharSequence searchStr,
CharSequence replacement)
替换字符串中的指定字符串,忽略大小写
|
static String |
reverse(String str)
反转字符串
例如:abcd =》dcba |
static double |
similar(String str1,
String str2)
计算两个字符串的相似度
|
static String |
similar(String str1,
String str2,
int scale)
计算连个字符串的相似度百分比
|
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 String[] |
split(CharSequence str,
CharSequence separator)
切分字符串
|
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 str,
char separator,
int limit)
切分字符串
|
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 isIgnoreCase)
是否以指定字符串开头
如果给定的字符串和开头字符串都为null则返回true,否则任意一个值为null返回false |
static boolean |
startWithAny(CharSequence str,
CharSequence... prefixes)
给定字符串是否以任何一个字符串开始
给定字符串和数组为空都返回false |
static boolean |
startWithIgnoreCase(CharSequence str,
CharSequence prefix)
是否以指定字符串开头,忽略大小写
|
static String |
str(byte[] data,
Charset charset)
解码字节码
|
static String |
str(Byte[] data,
Charset charset)
解码字节码
|
static String |
str(byte[] bytes,
String charset)
将byte数组转为字符串
|
static String |
str(Byte[] bytes,
String charset)
将Byte数组转为字符串
|
static String |
str(ByteBuffer data,
Charset charset)
将编码的byteBuffer数据转换为字符串
|
static String |
str(ByteBuffer data,
String charset)
将编码的byteBuffer数据转换为字符串
|
static String |
str(CharSequence cs)
CharSequence 转为字符串,null安全 |
static String |
str(Object obj,
Charset charset)
将对象转为字符串
1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法 |
static String |
str(Object obj,
String charsetName)
将对象转为字符串
1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法 |
static StrBuilder |
strBuilder()
创建StrBuilder对象
|
static StrBuilder |
strBuilder(CharSequence... strs)
创建StrBuilder对象
|
static StrBuilder |
strBuilder(int capacity)
创建StrBuilder对象
|
static String |
strip(CharSequence str,
CharSequence prefixOrSuffix)
去除两边的指定字符串
|
static String |
strip(CharSequence str,
CharSequence prefix,
CharSequence suffix)
去除两边的指定字符串
|
static String |
stripIgnoreCase(CharSequence str,
CharSequence prefixOrSuffix)
去除两边的指定字符串,忽略大小写
|
static String |
stripIgnoreCase(CharSequence str,
CharSequence prefix,
CharSequence suffix)
去除两边的指定字符串,忽略大小写
|
static String |
sub(CharSequence str,
int fromIndex,
int toIndex)
改进JDK subString
index从0开始计算,最后一个字符为-1 如果from和to位置一样,返回 "" 如果from或to为负数,则按照length从后向前数位置,如果绝对值大于字符串长度,则from归到0,to归到length 如果经过修正的index中from大于to,则互换from和to example: abcdefgh 2 3 =》 c abcdefgh 2 -3 =》 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 str,
CharSequence beforeAndAfter)
截取指定字符串中间部分,不包括标识字符串
|
static String |
subBetween(CharSequence str,
CharSequence before,
CharSequence after)
截取指定字符串中间部分,不包括标识字符串
|
static String[] |
subBetweenAll(CharSequence str,
CharSequence prefix,
CharSequence suffix)
截取指定字符串多段中间部分,不包括标识字符串
|
static String |
subByCodePoint(CharSequence str,
int fromIndex,
int toIndex)
通过CodePoint截取字符串,可以截断Emoji
|
static String |
subPre(CharSequence string,
int toIndex)
切割指定位置之前部分的字符串
|
static String |
subPreGbk(CharSequence str,
int len,
CharSequence suffix)
截取部分字符串,这里一个汉字的长度认为是2
|
static String |
subSuf(CharSequence string,
int fromIndex)
切割指定位置之后部分的字符串
|
static String |
subSufByLength(CharSequence string,
int length)
切割指定长度的后部分的字符串
|
static String |
subWithLength(String input,
int fromIndex,
int length)
截取字符串,从指定位置开始,截取指定长度的字符串
author weibaohui |
static String |
swapCase(String str)
切换给定字符串中的大小写。大写转小写,小写转大写。
|
static String |
toCamelCase(CharSequence name)
将下划线方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。
例如:hello_world=》helloWorld |
static String |
toLower(String oldData) |
static String |
toString(Object obj)
调用对象的toString方法,null会返回“null”
|
static String |
toSymbolCase(CharSequence str,
char symbol)
将驼峰式命名的字符串转换为使用符号连接方式。如果转换前的驼峰式命名的字符串为空,则返回空字符串。
|
static int |
totalLength(CharSequence... strs)
给定字符串数组的总长度
null字符长度定义为0 |
static String |
toUnderlineCase(CharSequence str)
将驼峰式命名的字符串转换为下划线方式。如果转换前的驼峰式命名的字符串为空,则返回空字符串。
例如: |
static String |
toUpper(String oldData) |
static String |
trim(CharSequence str)
除去字符串头尾部的空白,如果字符串是
null ,依然返回null 。 |
static String |
trim(CharSequence str,
int mode)
除去字符串头尾部的空白符,如果字符串是
null ,依然返回null 。 |
static void |
trim(String[] strs)
给定字符串数组全部做去首尾空格
|
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 ,返回"" 。 |
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 |
utf8Str(Object obj)
将对象转为字符串
1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法 |
static String |
uuid()
生成随机UUID
|
static String |
wrap(CharSequence str,
CharSequence prefixAndSuffix)
包装指定字符串
当前缀和后缀一致时使用此方法
|
static String |
wrap(CharSequence str,
CharSequence prefix,
CharSequence suffix)
包装指定字符串
|
static String[] |
wrapAll(CharSequence prefixAndSuffix,
CharSequence... strs)
包装多个字符串
|
static String[] |
wrapAll(CharSequence prefix,
CharSequence suffix,
CharSequence... strs)
包装多个字符串
|
static String[] |
wrapAllIfMissing(CharSequence prefixAndSuffix,
CharSequence... strs)
包装多个字符串,如果已经包装,则不再包装
|
static String[] |
wrapAllIfMissing(CharSequence prefix,
CharSequence suffix,
CharSequence... strs)
包装多个字符串,如果已经包装,则不再包装
|
static String |
wrapIfMissing(CharSequence str,
CharSequence prefix,
CharSequence suffix)
包装指定字符串,如果前缀或后缀已经包含对应的字符串,则不再包装
|
public static final int INDEX_NOT_FOUND
public static final char C_SPACE
public static final char C_TAB
public static final char C_DOT
public static final char C_SLASH
public static final char C_BACKSLASH
public static final char C_CR
public static final char C_LF
public static final char C_UNDERLINE
public static final char C_COMMA
public static final char C_DELIM_START
public static final char C_DELIM_END
public static final char C_BRACKET_START
public static final char C_BRACKET_END
public static final char C_COLON
public static final String SPACE
public static final String TAB
public static final String DOT
public static final String DOUBLE_DOT
public static final String SLASH
public static final String BACKSLASH
public static final String EMPTY
public static final String CR
public static final String LF
public static final String CRLF
public static final String UNDERLINE
public static final String DASHED
public static final String COMMA
public static final String DELIM_START
public static final String DELIM_END
public static final String BRACKET_START
public static final String BRACKET_END
public static final String COLON
public static final String HTML_NBSP
public static final String HTML_AMP
public static final String HTML_QUOTE
public static final String HTML_APOS
public static final String HTML_LT
public static final String HTML_GT
public static final String EMPTY_JSON
public static boolean isBlank(CharSequence str)
str
- 被检测的字符串public static boolean isBlankIfStr(Object obj)
obj
- 对象public static boolean isNotBlank(CharSequence str)
str
- 被检测的字符串public static boolean hasBlank(CharSequence... strs)
strs
- 字符串列表public static boolean isAllBlank(CharSequence... strs)
strs
- 字符串public static boolean isEmpty(CharSequence str)
str
- 被检测的字符串public static boolean isEmptyIfStr(Object obj)
obj
- 对象public static boolean isNotEmpty(CharSequence str)
str
- 被检测的字符串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
或者""或者空白,则返回指定默认字符串,否则返回字符串本身。
emptyToDefault(null, "default") = "default" emptyToDefault("", "default") = "default" emptyToDefault(" ", "default") = "default" emptyToDefault("bat", "default") = "bat"
str
- 要转换的字符串defaultStr
- 默认字符串public static String emptyToNull(CharSequence str)
null
str
- 被转换的字符串public static boolean hasEmpty(CharSequence... strs)
strs
- 字符串列表public static boolean isAllEmpty(CharSequence... strs)
strs
- 字符串列表public static boolean isAllNotEmpty(CharSequence... args)
null
或空对象,通过hasEmpty(CharSequence...)
判断元素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
不同,此方法使用NumberUtil.isBlankChar
来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
trim(null) = null trim("") = "" trim(" ") = "" trim("abc") = "abc" trim(" abc ") = "abc"
str
- 要处理的字符串null
,则返回null
public static void trim(String[] strs)
strs
- 字符串数组public static String trimToEmpty(CharSequence str)
null
,返回""
。
UStringUtil.trimToEmpty(null) = "" UStringUtil.trimToEmpty("") = "" UStringUtil.trimToEmpty(" ") = "" UStringUtil.trimToEmpty("abc") = "abc" UStringUtil.trimToEmpty(" abc ") = "abc"
str
- 字符串public static String trimToNull(CharSequence str)
null
,返回""
。
UStringUtil.trimToNull(null) = null UStringUtil.trimToNull("") = null UStringUtil.trimToNull(" ") = null UStringUtil.trimToNull("abc") = "abc" UStringUtil.trimToEmpty(" abc ") = "abc"
str
- 字符串public static String trimStart(CharSequence str)
null
,则返回null
。
注意,和String.trim
不同,此方法使用CharUtil.isBlankChar
来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
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
来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
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 boolean startWith(CharSequence str, char c)
str
- 字符串c
- 字符public static boolean startWith(CharSequence str, CharSequence prefix, boolean isIgnoreCase)
str
- 被监测字符串prefix
- 开头字符串isIgnoreCase
- 是否忽略大小写public static boolean startWith(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 endWith(CharSequence str, char c)
str
- 字符串c
- 字符public static boolean endWith(CharSequence str, CharSequence suffix, boolean isIgnoreCase)
str
- 被监测字符串suffix
- 结尾字符串isIgnoreCase
- 是否忽略大小写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 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)
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 String getGeneralField(CharSequence getOrSetMethodName)
getOrSetMethodName
- Get或Set方法名public static String genSetter(CharSequence fieldName)
fieldName
- 属性名public static String genGetter(CharSequence fieldName)
fieldName
- 属性名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 upperFirstAndAddPre(CharSequence str, String preString)
str
- 被处理的字符串preString
- 添加的首部public static String upperFirst(CharSequence str)
str
- 字符串public static String lowerFirst(CharSequence str)
str
- 字符串public static String removePrefix(CharSequence str, CharSequence prefix)
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 removeSufAndLowerFirst(CharSequence str, CharSequence suffix)
str
- 字符串suffix
- 后缀public static String removeSuffixIgnoreCase(CharSequence str, CharSequence suffix)
str
- 字符串suffix
- 后缀public static String strip(CharSequence str, CharSequence prefixOrSuffix)
str
- 被处理的字符串prefixOrSuffix
- 前缀或后缀public static String strip(CharSequence str, CharSequence prefix, CharSequence suffix)
str
- 被处理的字符串prefix
- 前缀suffix
- 后缀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 addPrefixIfNot(CharSequence str, CharSequence prefix)
str
- 字符串prefix
- 前缀public static String addSuffixIfNot(CharSequence str, CharSequence suffix)
str
- 字符串suffix
- 后缀public static String cleanBlank(CharSequence str)
str
- 被清理的字符串public static String[] splitToArray(CharSequence str, char separator)
str
- 被切分的字符串separator
- 分隔符字符public static String[] splitToArray(CharSequence str, char separator, int limit)
str
- 被切分的字符串separator
- 分隔符字符limit
- 限制分片数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 List<String> split(CharSequence str, char 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 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, CharSequence separator)
str
- 被切分的字符串separator
- 分隔符public static String[] split(CharSequence str, int len)
str
- 字符串len
- 每一个小节的长度StrSpliter.splitByLength(String, int)
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 String sub(CharSequence str, int fromIndex, int toIndex)
str
- StringfromIndex
- 开始的index(包括)toIndex
- 结束的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
- 切割的位置suffix
- 切割后加上后缀public static String maxLength(CharSequence string, int length)
string
- 字符串length
- 最大长度public static String subPre(CharSequence string, int toIndex)
string
- 字符串toIndex
- 切割到的位置(不包括)public static String subSuf(CharSequence string, int fromIndex)
string
- 字符串fromIndex
- 切割开始的位置(包括)public static String subSufByLength(CharSequence string, int length)
UStringUtil.subSufByLength("abcde", 3) = "cde" UStringUtil.subSufByLength("abcde", 0) = "" UStringUtil.subSufByLength("abcde", -5) = "" UStringUtil.subSufByLength("abcde", -1) = "" UStringUtil.subSufByLength("abcde", 5) = "abcde" UStringUtil.subSufByLength("abcde", 10) = "abcde" UStringUtil.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)
UStringUtil.subBefore(null, *) = null UStringUtil.subBefore("", *) = "" UStringUtil.subBefore("abc", "a") = "" UStringUtil.subBefore("abcba", "b") = "a" UStringUtil.subBefore("abc", "c") = "ab" UStringUtil.subBefore("abc", "d") = "abc" UStringUtil.subBefore("abc", "") = "" UStringUtil.subBefore("abc", null) = "abc"
string
- 被查找的字符串separator
- 分隔字符串(不包括)isLastSeparator
- 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个public static String subBefore(CharSequence string, char separator, boolean isLastSeparator)
UStringUtil.subBefore(null, *) = null UStringUtil.subBefore("", *) = "" UStringUtil.subBefore("abc", 'a') = "" UStringUtil.subBefore("abcba", 'b') = "a" UStringUtil.subBefore("abc", 'c') = "ab" UStringUtil.subBefore("abc", 'd') = "abc"
string
- 被查找的字符串separator
- 分隔字符串(不包括)isLastSeparator
- 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个public static String subAfter(CharSequence string, CharSequence separator, boolean isLastSeparator)
UStringUtil.subAfter(null, *) = null UStringUtil.subAfter("", *) = "" UStringUtil.subAfter(*, null) = "" UStringUtil.subAfter("abc", "a") = "bc" UStringUtil.subAfter("abcba", "b") = "cba" UStringUtil.subAfter("abc", "c") = "" UStringUtil.subAfter("abc", "d") = "" UStringUtil.subAfter("abc", "") = "abc"
string
- 被查找的字符串separator
- 分隔字符串(不包括)isLastSeparator
- 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个public static String subAfter(CharSequence string, char separator, boolean isLastSeparator)
UStringUtil.subAfter(null, *) = null UStringUtil.subAfter("", *) = "" UStringUtil.subAfter("abc", 'a') = "bc" UStringUtil.subAfter("abcba", 'b') = "cba" UStringUtil.subAfter("abc", 'c') = "" UStringUtil.subAfter("abc", 'd') = ""
string
- 被查找的字符串separator
- 分隔字符串(不包括)isLastSeparator
- 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个public static String subBetween(CharSequence str, CharSequence before, CharSequence after)
栗子:
UStringUtil.subBetween("wx[b]yz", "[", "]") = "b" UStringUtil.subBetween(null, *, *) = null UStringUtil.subBetween(*, null, *) = null UStringUtil.subBetween(*, *, null) = null UStringUtil.subBetween("", "", "") = "" UStringUtil.subBetween("", "", "]") = null UStringUtil.subBetween("", "[", "]") = null UStringUtil.subBetween("yabcz", "", "") = "" UStringUtil.subBetween("yabcz", "y", "z") = "abc" UStringUtil.subBetween("yabczyabcz", "y", "z") = "abc"
str
- 被切割的字符串before
- 截取开始的字符串标识after
- 截取到的字符串标识public static String subBetween(CharSequence str, CharSequence beforeAndAfter)
栗子:
UStringUtil.subBetween(null, *) = null UStringUtil.subBetween("", "") = "" UStringUtil.subBetween("", "tag") = null UStringUtil.subBetween("tagabctag", null) = null UStringUtil.subBetween("tagabctag", "") = "" UStringUtil.subBetween("tagabctag", "tag") = "abc"
str
- 被切割的字符串beforeAndAfter
- 截取开始和结束的字符串标识public static String[] subBetweenAll(CharSequence str, CharSequence prefix, CharSequence suffix)
栗子:
UStringUtil.subBetweenAll("wx[b]y[z]", "[", "]") = ["b","z"] UStringUtil.subBetweenAll(null, *, *) = [] UStringUtil.subBetweenAll(*, null, *) = [] UStringUtil.subBetweenAll(*, *, null) = [] UStringUtil.subBetweenAll("", "", "") = [] UStringUtil.subBetweenAll("", "", "]") = [] UStringUtil.subBetweenAll("", "[", "]") = [] UStringUtil.subBetweenAll("yabcz", "", "") = [] UStringUtil.subBetweenAll("yabcz", "y", "z") = ["abc"] UStringUtil.subBetweenAll("yabczyabcz", "y", "z") = ["abc","abc"] UStringUtil.subBetweenAll("[yabc[zy]abcz]", "[", "]"); = ["zy"] 重叠时只截取内部,
str
- 被切割的字符串prefix
- 截取开始的字符串标识suffix
- 截取到的字符串标识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 String repeat(char c, int count)
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 conjunction)
UStringUtil.repeatAndJoin("?", 5, ",") = "?,?,?,?,?" UStringUtil.repeatAndJoin("?", 0, ",") = "" UStringUtil.repeatAndJoin("?", 5, null) = "?????"
str
- 被重复的字符串count
- 数量conjunction
- 分界符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)
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 String format(CharSequence template, Object... params)
template
- 文本模板,被替换的部分用 {} 表示params
- 参数值public static String indexedFormat(CharSequence pattern, Object... arguments)
pattern
- 文本格式arguments
- 参数public static String format(CharSequence template, Map<?,?> map)
template
- 文本模板,被替换的部分用 {key} 表示map
- 参数值对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 String utf8Str(Object obj)
obj
- 对象public static String str(Object obj, String charsetName)
obj
- 对象charsetName
- 字符集public static String str(Object obj, Charset charset)
obj
- 对象charset
- 字符集public static String str(byte[] bytes, String charset)
bytes
- byte数组charset
- 字符集public static String str(byte[] data, Charset charset)
data
- 字符串charset
- 字符集,如果此字段为空,则解码的结果取决于平台public static String str(Byte[] bytes, String charset)
bytes
- byte数组charset
- 字符集public static String str(Byte[] data, Charset charset)
data
- 字符串charset
- 字符集,如果此字段为空,则解码的结果取决于平台public static String str(ByteBuffer data, String charset)
data
- 数据charset
- 字符集,如果为空使用当前系统字符集public static String str(ByteBuffer data, Charset charset)
data
- 数据charset
- 字符集,如果为空使用当前系统字符集public static String str(CharSequence cs)
CharSequence
转为字符串,null安全cs
- CharSequence
public static String toString(Object obj)
obj
- 对象public static ByteBuffer byteBuffer(CharSequence str, String charset)
str
- 字符串charset
- 编码public static String join(CharSequence conjunction, Object... objs)
conjunction
- 分隔符objs
- 数组UArrayUtil.join(Object, CharSequence)
public static String toUnderlineCase(CharSequence str)
HelloWorld=》hello_world Hello_World=》hello_world HelloWorld_test=》hello_world_test
str
- 转换前的驼峰式命名的字符串,也可以为下划线形式public static String toSymbolCase(CharSequence str, char symbol)
str
- 转换前的驼峰式命名的字符串,也可以为符号连接形式symbol
- 连接符public static String toCamelCase(CharSequence name)
name
- 转换前的下划线大写方式命名的字符串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[] wrapAll(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[] wrapAllIfMissing(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 minLength, CharSequence padStr)
UStringUtil.padPre(null, *, *);//null UStringUtil.padPre("1", 3, "ABC");//"AB1" UStringUtil.padPre("123", 2, "ABC");//"12"
str
- 字符串minLength
- 最小长度padStr
- 补充的字符public static String padPre(CharSequence str, int minLength, char padChar)
UStringUtil.padPre("1", 3, '0');//"001"
str
- 字符串minLength
- 最小长度padChar
- 补充的字符public static String padAfter(CharSequence str, int minLength, char padChar)
UStringUtil.padAfter(null, *, *);//null UStringUtil.padAfter("1", 3, '0');//"100" UStringUtil.padAfter("123", 2, '0');//"23"
str
- 字符串,如果为null
,直接返回nullminLength
- 最小长度padChar
- 补充的字符public static String padAfter(CharSequence str, int minLength, CharSequence padStr)
UStringUtil.padAfter(null, *, *);//null UStringUtil.padAfter("1", 3, "ABC");//"1AB" UStringUtil.padAfter("123", 2, "ABC");//"23"
str
- 字符串,如果为null
,直接返回nullminLength
- 最小长度padStr
- 补充的字符@Deprecated public static String padEnd(CharSequence str, int minLength, char padChar)
padAfter(CharSequence str, int minLength, char padChar)
UStringUtil.padEnd("1", 3, '0');//"100"
str
- 字符串,如果为null
,按照空串处理minLength
- 最小长度padChar
- 补充的字符public static String center(CharSequence str, int size)
UStringUtil.center(null, *) = null UStringUtil.center("", 4) = " " UStringUtil.center("ab", -1) = "ab" UStringUtil.center("ab", 4) = " ab " UStringUtil.center("abcd", 2) = "abcd" UStringUtil.center("a", 4) = " a "
str
- 字符串size
- 指定长度public static String center(CharSequence str, int size, char padChar)
UStringUtil.center(null, *, *) = null UStringUtil.center("", 4, ' ') = " " UStringUtil.center("ab", -1, ' ') = "ab" UStringUtil.center("ab", 4, ' ') = " ab " UStringUtil.center("abcd", 2, ' ') = "abcd" UStringUtil.center("a", 4, ' ') = " a " UStringUtil.center("a", 4, 'y') = "yayy" UStringUtil.center("abc", 7, ' ') = " abc "
str
- 字符串size
- 指定长度padChar
- 两边补充的字符public static String center(CharSequence str, int size, CharSequence padStr)
UStringUtil.center(null, *, *) = null UStringUtil.center("", 4, " ") = " " UStringUtil.center("ab", -1, " ") = "ab" UStringUtil.center("ab", 4, " ") = " ab " UStringUtil.center("abcd", 2, " ") = "abcd" UStringUtil.center("a", 4, " ") = " a " UStringUtil.center("a", 4, "yz") = "yayz" UStringUtil.center("abc", 7, null) = " abc " UStringUtil.center("abc", 7, "") = " abc "
str
- 字符串size
- 指定长度padStr
- 两边补充的字符串public static StringBuilder builder()
public static StrBuilder strBuilder()
public static StringBuilder builder(int capacity)
capacity
- 初始大小public static StrBuilder strBuilder(int capacity)
capacity
- 初始大小public static StringBuilder builder(CharSequence... strs)
strs
- 初始字符串列表public static StrBuilder strBuilder(CharSequence... strs)
strs
- 初始字符串列表public static StringReader getReader(CharSequence str)
str
- 字符串public static StringWriter getWriter()
public static int count(CharSequence content, CharSequence strForSearch)
null
或者 "" 返回 0
.
UStringUtil.count(null, *) = 0 UStringUtil.count("", *) = 0 UStringUtil.count("abba", null) = 0 UStringUtil.count("abba", "") = 0 UStringUtil.count("abba", "a") = 2 UStringUtil.count("abba", "ab") = 1 UStringUtil.count("abba", "xxx") = 0
content
- 被查找的字符串strForSearch
- 需要查找的字符串public static int count(CharSequence content, char charForSearch)
content
- 内容charForSearch
- 被统计的字符public static String[] cut(CharSequence str, int partLength)
str
- 字符串partLength
- 每等份的长度public static String brief(CharSequence str, int maxLength)
str
- 字符串maxLength
- 最大长度public static int compare(CharSequence str1, CharSequence str2, boolean nullIsLess)
UStringUtil.compare(null, null, *) = 0 UStringUtil.compare(null , "a", true) < 0 UStringUtil.compare(null , "a", false) > 0 UStringUtil.compare("a", null, true) > 0 UStringUtil.compare("a", null, false) < 0 UStringUtil.compare("abc", "abc", *) = 0 UStringUtil.compare("a", "b", *) < 0 UStringUtil.compare("b", "a", *) > 0 UStringUtil.compare("a", "B", *) > 0 UStringUtil.compare("ab", "abc", *) < 0
str1
- 字符串1str2
- 字符串2nullIsLess
- null
值是否排在前(null是否小于非空值)public static int compareIgnoreCase(CharSequence str1, CharSequence str2, boolean nullIsLess)
UStringUtil.compareIgnoreCase(null, null, *) = 0 UStringUtil.compareIgnoreCase(null , "a", true) < 0 UStringUtil.compareIgnoreCase(null , "a", false) > 0 UStringUtil.compareIgnoreCase("a", null, true) > 0 UStringUtil.compareIgnoreCase("a", null, false) < 0 UStringUtil.compareIgnoreCase("abc", "abc", *) = 0 UStringUtil.compareIgnoreCase("abc", "ABC", *) = 0 UStringUtil.compareIgnoreCase("a", "b", *) < 0 UStringUtil.compareIgnoreCase("b", "a", *) > 0 UStringUtil.compareIgnoreCase("a", "B", *) < 0 UStringUtil.compareIgnoreCase("A", "b", *) < 0 UStringUtil.compareIgnoreCase("ab", "abc", *) < 0
str1
- 字符串1str2
- 字符串2nullIsLess
- null
值是否排在前(null是否小于非空值)public static int compareVersion(CharSequence version1, CharSequence version2)
UStringUtil.compareVersion(null, "v1") < 0 UStringUtil.compareVersion("v1", "v1") = 0 UStringUtil.compareVersion(null, null) = 0 UStringUtil.compareVersion("v1", null) > 0 UStringUtil.compareVersion("1.0.0", "1.0.2") < 0 UStringUtil.compareVersion("1.0.2", "1.0.2a") < 0 UStringUtil.compareVersion("1.13.0", "1.12.1c") > 0 UStringUtil.compareVersion("V0.0.20170102", "V0.0.20170101") > 0
version1
- 版本1version2
- 版本2public 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 str, char searchChar, int start, int end)
str
- 字符串searchChar
- 被查找的字符start
- 起始位置,如果小于0,从0开始查找end
- 终止位置,如果超过str.length()则默认查找到字符串末尾public static int indexOfIgnoreCase(CharSequence str, CharSequence searchStr)
UStringUtil.indexOfIgnoreCase(null, *, *) = -1 UStringUtil.indexOfIgnoreCase(*, null, *) = -1 UStringUtil.indexOfIgnoreCase("", "", 0) = 0 UStringUtil.indexOfIgnoreCase("aabaabaa", "A", 0) = 0 UStringUtil.indexOfIgnoreCase("aabaabaa", "B", 0) = 2 UStringUtil.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1 UStringUtil.indexOfIgnoreCase("aabaabaa", "B", 3) = 5 UStringUtil.indexOfIgnoreCase("aabaabaa", "B", 9) = -1 UStringUtil.indexOfIgnoreCase("aabaabaa", "B", -1) = 2 UStringUtil.indexOfIgnoreCase("aabaabaa", "", 2) = 2 UStringUtil.indexOfIgnoreCase("abc", "", 9) = -1
str
- 字符串searchStr
- 需要查找位置的字符串public static int indexOfIgnoreCase(CharSequence str, CharSequence searchStr, int fromIndex)
UStringUtil.indexOfIgnoreCase(null, *, *) = -1 UStringUtil.indexOfIgnoreCase(*, null, *) = -1 UStringUtil.indexOfIgnoreCase("", "", 0) = 0 UStringUtil.indexOfIgnoreCase("aabaabaa", "A", 0) = 0 UStringUtil.indexOfIgnoreCase("aabaabaa", "B", 0) = 2 UStringUtil.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1 UStringUtil.indexOfIgnoreCase("aabaabaa", "B", 3) = 5 UStringUtil.indexOfIgnoreCase("aabaabaa", "B", 9) = -1 UStringUtil.indexOfIgnoreCase("aabaabaa", "B", -1) = 2 UStringUtil.indexOfIgnoreCase("aabaabaa", "", 2) = 2 UStringUtil.indexOfIgnoreCase("abc", "", 9) = -1
str
- 字符串searchStr
- 需要查找位置的字符串fromIndex
- 起始位置public static int indexOf(CharSequence str, CharSequence searchStr, int fromIndex, boolean ignoreCase)
str
- 字符串searchStr
- 需要查找位置的字符串fromIndex
- 起始位置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 str, CharSequence searchStr, int fromIndex, boolean ignoreCase)
str
- 字符串searchStr
- 需要查找位置的字符串fromIndex
- 起始位置,从后往前计数ignoreCase
- 是否忽略大小写public static int ordinalIndexOf(String str, String searchStr, int ordinal)
栗子(*代表任意字符):
UStringUtil.ordinalIndexOf(null, *, *) = -1 UStringUtil.ordinalIndexOf(*, null, *) = -1 UStringUtil.ordinalIndexOf("", "", *) = 0 UStringUtil.ordinalIndexOf("aabaabaa", "a", 1) = 0 UStringUtil.ordinalIndexOf("aabaabaa", "a", 2) = 1 UStringUtil.ordinalIndexOf("aabaabaa", "b", 1) = 2 UStringUtil.ordinalIndexOf("aabaabaa", "b", 2) = 5 UStringUtil.ordinalIndexOf("aabaabaa", "ab", 1) = 1 UStringUtil.ordinalIndexOf("aabaabaa", "ab", 2) = 4 UStringUtil.ordinalIndexOf("aabaabaa", "", 1) = 0 UStringUtil.ordinalIndexOf("aabaabaa", "", 2) = 0
str
- 被检查的字符串,可以为nullsearchStr
- 被查找的字符串,可以为nullordinal
- 第几次出现的位置public 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... suffixes)
str
- 被检查的字符串suffix
- 需要添加到结尾的字符串ignoreCase
- 检查结尾时是否忽略大小写suffixes
- 需要额外检查的结尾字符串,如果以这些中的一个为结尾,则不再添加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 reverse(String str)
str
- 被反转的字符串public static String fillBefore(String str, char filledChar, int len)
str
- 被填充的字符串filledChar
- 填充的字符len
- 填充长度public static String fillAfter(String str, char filledChar, int len)
str
- 被填充的字符串filledChar
- 填充的字符len
- 填充长度public static String fill(String str, char filledChar, int len, boolean isPre)
str
- 被填充的字符串filledChar
- 填充的字符len
- 填充长度isPre
- 是否填充在前public static boolean isSubEquals(CharSequence str1, int start1, CharSequence str2, int start2, int length, boolean ignoreCase)
str1
- 第一个字符串start1
- 第一个字符串开始的位置str2
- 第二个字符串start2
- 第二个字符串开始的位置length
- 截取长度ignoreCase
- 是否忽略大小写public static boolean isAllCharMatch(CharSequence value, Matcher<Character> matcher)
value
- 字符串matcher
- 匹配器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
- 是否忽略大小写public static String replace(CharSequence str, int startInclude, int endExclude, char replacedChar)
str
- 字符串startInclude
- 开始位置(包含)endExclude
- 结束位置(不包含)replacedChar
- 被替换的字符public static String replace(CharSequence str, Pattern pattern, Func1<Matcher,String> replaceFun)
str
- 要替换的字符串pattern
- 用于匹配的正则式replaceFun
- 决定如何替换的函数UReUtil.replaceAll(CharSequence, Pattern, Func1)
public static String replace(CharSequence str, String regex, Func1<Matcher,String> replaceFun)
str
- 要替换的字符串regex
- 用于匹配的正则式replaceFun
- 决定如何替换的函数UReUtil.replaceAll(CharSequence, String, Func1)
public static String hide(CharSequence str, int startInclude, int endExclude)
str
- 字符串startInclude
- 开始位置(包含)endExclude
- 结束位置(不包含)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 double similar(String str1, String str2)
str1
- 字符串1str2
- 字符串2public static String similar(String str1, String str2, int scale)
str1
- 字符串1str2
- 字符串2scale
- 保留小数public static boolean equalsCharAt(CharSequence str, int position, char c)
str
- 字符串position
- 位置c
- 需要对比的字符public static int totalLength(CharSequence... strs)
strs
- 字符串数组public static String move(CharSequence str, int startInclude, int endExclude, int moveLength)
str
- 字符串startInclude
- 起始位置(包括)endExclude
- 结束位置(不包括)moveLength
- 移动距离,负数表示左移,正数为右移public static String uuid()
UIdUtil.randomUUID()
public static String concat(boolean isNullToEmpty, CharSequence... strs)
isNullToEmpty
- 是否null转为""strs
- 字符串数组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 int length(CharSequence cs)
cs
- a 字符串public static int byteLength(CharSequence cs, Charset charset)
cs
- 字符串charset
- 编码public static String swapCase(String str)
UStringUtil.swapCase(null) = null UStringUtil.swapCase("") = "" UStringUtil.swapCase("The dog has a BONE") = "tHE DOG HAS A bone"
str
- 字符串Copyright © 2020. All rights reserved.