public class Strings extends Object
Modifier and Type | Field and Description |
---|---|
static String |
EMPTY |
static String |
SPACE |
Modifier and Type | Method and Description |
---|---|
static String |
appendAround(String s,
String prefix,
String suffix)
拼接字符串
|
static String |
build(Appendable build,
Object... obj)
构建字符串
|
static String |
build(Object... obj)
构建字符串 (StringBuild)
|
static byte[] |
bytes(String s)
获取byte[]
|
static byte[] |
bytes(String s,
Charset charset)
获取byte[]
|
static byte[] |
bytes(String s,
String charset)
获取byte[]
|
static String |
centerOmit(String str,
int leftLength,
int length) |
static String |
centerOmit(String str,
int leftLength,
int length,
String omit)
省略字符串中间
[1, 3] 1234567 1...67
[2, 3] 1234567 12...7
[2, 4] 1234567 1234567
|
static String |
centerPad(String str,
int size)
中间用空格补齐到规定长度
.center(null, *) = null
.center(Strings.EMPTY, 4) = " "
.center("ab", -1) = "ab"
.center("ab", 4) = " ab "
.center("abc", 2) = "abc"
.center("a", 4) = " a "
|
static String |
centerPad(String str,
int size,
char padChar) |
static String |
centerPad(String str,
int size,
String padStr) |
static String |
charset(String s,
String charset)
转码
|
static String |
charset(String s,
String oldCharset,
String newCharset)
转码
|
static boolean |
contains(String s,
String contains)
检查是否包含
|
static boolean |
containsAll(String s,
Collection<String> contains)
检查是否包含所有项
|
static boolean |
containsAny(String s,
Collection<String> contains)
检查是否包含任意项
|
static boolean |
containsNone(String s,
Collection<String> contains)
检查是否不包含
|
static boolean |
containsNone(String s,
String contains)
检查是否不包含
|
static String |
def(String str) |
static String |
def(String str,
String def) |
static String |
def(String str,
Supplier<String> def)
默认值
|
static boolean |
endWith(String s,
String end)
是否为end结尾
|
static boolean |
eq(Object o1,
Object o2)
比较字符串是否相等
|
static boolean |
eq(String str1,
String str2)
比较字符串是否相等
|
static int |
findNum(String s,
String find)
匹配字符出现次数
|
static String |
firstLower(Object obj)
小写首字母
|
static String |
firstUpper(Object obj)
大写首字母
|
static String |
format(String str,
Map<?,?> map)
格式化字符串 ${}
|
static String |
format(String str,
Object... args)
模板字符串
|
static String |
format(String str,
String replacement,
Map<?,?> map)
格式化字符串 replacement{}
这里多层数据结构就会有问题 可以使用
ReplacementFormatters |
static String |
fullToHalf(String s)
全角字符变半角字符
|
static int[] |
getCodePoints(String s)
获取字符串码点
|
static String |
halfToFull(String s)
半角字符变全角字符
|
static String |
ifBlank(String s) |
static String |
ifBlank(String s,
String def) |
static String |
ifBlank(String s,
Supplier<String> def)
如果为空串返回默认值
|
static String |
ifEmpty(String s) |
static String |
ifEmpty(String s,
String def) |
static String |
ifEmpty(String s,
Supplier<String> def)
如果为空返回默认值
|
static void |
ifNotBlank(String s,
Consumer<String> acceptor)
非空执行
|
static void |
ifNotEmpty(String s,
Consumer<String> acceptor)
非空执行
|
static boolean |
ignoreEq(Object o1,
Object o2)
比较字符串是否相等(不区分大小写)
|
static boolean |
isAllBlank(String... strs)
是否全部为空
|
static boolean |
isAllDouble(String... strs)
是否全部为浮点数
|
static boolean |
isAllEmpty(CharSequence... strs)
是否全部为空
|
static boolean |
isAllInteger(String... strs)
是否全部为整数数
|
static boolean |
isAllNumber(String... strs)
是否全部为数字
|
static boolean |
isAnyBlank(String... strs)
验证是否有为空
|
static boolean |
isAnyEmpty(String... strs)
验证是否有为空
|
static boolean |
isBlank(String str)
检查是否为空
|
static boolean |
isDouble(String str)
是否为浮点数数(正则)
|
static boolean |
isEmpty(CharSequence str)
检查是否为空
|
static boolean |
isInteger(String str)
是否为整数(正则)
|
static boolean |
isIntegerASCII(String str)
是否为整数(ASCII)
|
static boolean |
isNoneBlank(String... strs)
验证是否没有为空
|
static boolean |
isNoneDouble(String... strs)
是否全部不为浮点数
|
static boolean |
isNoneEmpty(CharSequence... strs)
验证是否没有为空
|
static boolean |
isNoneInteger(String... strs)
是否全部不为浮点数
|
static boolean |
isNoneNumber(String... strs)
是否全部不为数字
|
static boolean |
isNotBlank(String str)
检查是否不为空
|
static boolean |
isNotDouble(String str)
是否不为浮点数数(正则)
|
static boolean |
isNotEmpty(CharSequence str)
检查是否不为空
|
static boolean |
isNotInteger(String str)
是否不为整数
|
static boolean |
isNotNumber(String str)
是否不为数字
|
static boolean |
isNumber(String str)
是否为数字
|
static String |
join(Collection<String> list,
String delimiter) |
static String |
join(Collection<String> list,
String delimiter,
String prefix,
String suffix)
连接字符串
|
static String |
join(String... strs) |
static String |
joinWith(String delimiter,
String... strs)
连接字符串
|
static String |
leftPad(String str,
int size)
左侧用空格补齐到规定长度
leftPad(null, *) = null
leftPad(Strings.EMPTY, 3) = " "
leftPad("abc", 3) = "abc"
leftPad("abc", 5) = " abc"
leftPad("abc", 1) = "abc"
leftPad("abc", -1) = "abc"
|
static String |
leftPad(String str,
int size,
char padChar) |
static String |
leftPad(String str,
int size,
String padStr) |
static int |
length(String s)
字符串长度
|
static int |
length(String s,
boolean trim)
字符串长度
|
static StringBuffer |
newBuffer() |
static StringBuffer |
newBuffer(int capacity) |
static StringBuffer |
newBuffer(String s) |
static StringBuilder |
newBuilder() |
static StringBuilder |
newBuilder(int capacity)
创建StringBuilder对象
|
static StringBuilder |
newBuilder(String s) |
static String |
omit(String str,
int length) |
static String |
omit(String str,
int length,
String omit)
省略字符串结尾
[3] 1234567 123
|
static String |
randomChar()
随机一个中文汉字
|
static String |
randomChars(int count)
随机几个个中文汉字
|
static String |
repeat(char c,
int num)
重复字符串
|
static String |
repeat(String str,
int num)
重复字符串
|
static char[] |
repeatArr(String str,
int num)
重复字符串
|
static String |
replace(String s,
String o,
String t)
替换字符串
|
static String |
replaceAll(String s,
String reg,
String t)
替换字符串
|
static String |
replaceCRLF(String s)
替换 \r \r\n -> \n
|
static String |
retain(String str,
int length)
保留长度
|
static String |
rightPad(String str,
int size)
右侧用空格补齐到规定长度
rightPad(null, *) = null
rightPad(Strings.EMPTY, 3) = " "
rightPad("abc", 3) = "abc"
rightPad("abc", 5) = "abc "
rightPad("abc", 1) = "abc"
rightPad("abc", -1) = "abc"
|
static String |
rightPad(String str,
int size,
char padChar) |
static String |
rightPad(String str,
int size,
String padStr) |
static String |
skip(String str,
int skip)
跳过字符串开头
|
static boolean |
some(String str,
String... strs)
判断至少包含一个相同的值
|
static void |
split(String str,
String tokenizer,
Consumer<String> consumer)
切分
|
static boolean |
startWith(String s,
String start)
是否为start开头
|
static String |
str(Object obj)
创建字符串(UTF-8)
|
static String |
str(Object obj,
String charset)
创建字符串
|
static String |
substringAfter(String s,
String separator)
截取第一个分隔符之后字符串
|
static String |
substringAfterLast(String s,
String separator)
截取最后一个分隔符之后字符串
|
static String |
substringBefore(String s,
String separator)
截取第一个分隔符之前字符串
|
static String |
substringBeforeLast(String s,
String separator)
截取最后一个分隔符之前字符串
|
static String |
toASCII(String s)
ASCII编码
|
static String |
toGBK(String s)
GBK编码
|
static String |
toUTF8(String s)
UTF8编码
|
static boolean |
trimEq(Object o1,
Object o2)
比较字符串是否相等 (去除首尾空格)
|
static String |
trimPunct(String s)
删除所有的标点符号
|
public static final String EMPTY
public static final String SPACE
public static String str(Object obj, String charset)
obj
- 字符对象charset
- 编码格式public static int length(String s)
s
- 字符串public static int length(String s, boolean trim)
s
- 字符串trim
- 是否去除头尾空格public static String def(String str, Supplier<String> def)
str
- 字符串def
- 默认值public static String ifBlank(String s, Supplier<String> def)
s
- sdef
- defpublic static String ifEmpty(String s, Supplier<String> def)
s
- sdef
- defpublic static void ifNotBlank(String s, Consumer<String> acceptor)
s
- sacceptor
- acceptorpublic static void ifNotEmpty(String s, Consumer<String> acceptor)
s
- sacceptor
- acceptorpublic static boolean isBlank(String str)
str
- 待验证的字符串public static boolean isNotBlank(String str)
str
- 待验证的字符串public static boolean isAllBlank(String... strs)
strs
- 参数为空返回为 truepublic static boolean isAnyBlank(String... strs)
strs
- 参数为空返回为 falsepublic static boolean isNoneBlank(String... strs)
strs
- 参数为空返回为 falsepublic static boolean isEmpty(CharSequence str)
str
- 待验证的字符串public static boolean isNotEmpty(CharSequence str)
str
- 待验证的字符串public static boolean isAllEmpty(CharSequence... strs)
strs
- 参数为空返回为 truepublic static boolean isAnyEmpty(String... strs)
strs
- 参数为空返回为 falsepublic static boolean isNoneEmpty(CharSequence... strs)
strs
- 参数为空返回为 falsepublic static boolean isInteger(String str)
str
- 待验证的字符串public static boolean isNotInteger(String str)
str
- 待验证的字符串public static boolean isAllInteger(String... strs)
strs
- 待验证的一组字符串, 参数为空返回为truepublic static boolean isNoneInteger(String... strs)
strs
- 待验证的一组字符串, 参数为空返回为truepublic static boolean isIntegerASCII(String str)
str
- 待验证的字符串public static boolean isDouble(String str)
str
- 待验证的字符串public static boolean isNotDouble(String str)
str
- 待验证的字符串public static boolean isAllDouble(String... strs)
strs
- 待验证的一组字符串, 参数为空返回为truepublic static boolean isNoneDouble(String... strs)
strs
- 待验证的一组字符串, 参数为空返回为truepublic static boolean isNumber(String str)
str
- 待验证的字符串public static boolean isNotNumber(String str)
str
- 待验证的字符串public static boolean isAllNumber(String... strs)
strs
- 待验证的一组字符串, 参数为空返回为truepublic static boolean isNoneNumber(String... strs)
strs
- 待验证的一组字符串, 参数为空返回为truepublic static boolean startWith(String s, String start)
s
- ignorestart
- ignorepublic static boolean endWith(String s, String end)
s
- ignoreend
- ignorepublic static String substringBefore(String s, String separator)
s
- ignoreseparator
- 分隔符public static String substringBeforeLast(String s, String separator)
s
- ignoreseparator
- 分隔符public static String substringAfter(String s, String separator)
s
- ignoreseparator
- 分隔符public static String substringAfterLast(String s, String separator)
s
- ignoreseparator
- 分隔符public static void split(String str, String tokenizer, Consumer<String> consumer)
str
- 待切分的字符串tokenizer
- 分隔符consumer
- 消费public static String joinWith(String delimiter, String... strs)
strs
- 连接字符串delimiter
- delimiterpublic static String join(Collection<String> list, String delimiter)
public static String join(Collection<String> list, String delimiter, String prefix, String suffix)
list
- 连接字符串delimiter
- delimiterprefix
- 前缀suffix
- 后缀public static String appendAround(String s, String prefix, String suffix)
s
- 拼接字符串到前后prefix
- 前缀suffix
- 后缀public static String replace(String s, String o, String t)
s
- 字符串o
- 原字符t
- 新字符串public static String replaceAll(String s, String reg, String t)
s
- 字符串reg
- 正则t
- 新字符串public static String randomChar()
public static String randomChars(int count)
count
- 汉字数量public static String format(String str, Object... args)
str
- 模板args
- 参数public static String format(String str, Map<?,?> map)
str
- 字符串map
- ${key} = valuepublic static String format(String str, String replacement, Map<?,?> map)
这里多层数据结构就会有问题 可以使用 ReplacementFormatters
str
- 字符串map
- replacement{key} = valuepublic static String build(Object... obj)
obj
- 字符对象public static String build(Appendable build, Object... obj)
build
- 构建对象obj
- 字符对象public static StringBuilder newBuilder()
public static StringBuilder newBuilder(String s)
public static StringBuilder newBuilder(int capacity)
capacity
- 初始化容量public static StringBuffer newBuffer()
public static StringBuffer newBuffer(String s)
public static StringBuffer newBuffer(int capacity)
public static boolean eq(Object o1, Object o2)
o1
- 对象1o2
- 对象2public static boolean trimEq(Object o1, Object o2)
o1
- 对象1o2
- 对象2public static boolean ignoreEq(Object o1, Object o2)
o1
- 对象1o2
- 对象2public static boolean eq(String str1, String str2)
str1
- 字符1str2
- 字符2public static boolean some(String str, String... strs)
str
- 判断的值strs
- 给定的一组值public static String fullToHalf(String s)
s
- 需要处理的字符串public static String halfToFull(String s)
s
- 需要处理的字符串public static String repeat(String str, int num)
str
- 字符串num
- 重复次数public static String repeat(char c, int num)
c
- 字符num
- 重复次数public static char[] repeatArr(String str, int num)
str
- 字符串num
- 重复次数public static int findNum(String s, String find)
s
- 源数据find
- 匹配数据public static String skip(String str, int skip)
str
- 字符串skip
- 跳过几位public static String retain(String str, int length)
str
- strlength
- lengthpublic static String omit(String str, int length, String omit)
[3] 1234567 123... [4] 1234567 1234567
str
- 字符串length
- 保留几位omit
- 省略符public static String centerOmit(String str, int leftLength, int length, String omit)
[1, 3] 1234567 1...67 [2, 3] 1234567 12...7 [2, 4] 1234567 1234567
str
- 字符串length
- 左侧保留几位length
- 总共保留几位omit
- 省略符public static String charset(String s, String oldCharset, String newCharset)
s
- ignoreoldCharset
- 原编码格式newCharset
- 新编码格式public static String charset(String s, String charset)
s
- ignorecharset
- 原编码格式public static String rightPad(String str, int size)
str
- 字符串size
- 长度public static String leftPad(String str, int size)
str
- 字符串size
- 长度public static String centerPad(String str, int size)
str
- 字符串size
- 长度public static int[] getCodePoints(String s)
s
- spublic static byte[] bytes(String s)
s
- spublic static byte[] bytes(String s, Charset charset)
s
- scharset
- charsetpublic static byte[] bytes(String s, String charset)
s
- scharset
- charsetpublic static String replaceCRLF(String s)
s
- spublic static boolean contains(String s, String contains)
s
- scontains
- containspublic static boolean containsAny(String s, Collection<String> contains)
s
- scontains
- 包含项public static boolean containsAll(String s, Collection<String> contains)
s
- scontains
- containspublic static boolean containsNone(String s, String contains)
s
- scontains
- containspublic static boolean containsNone(String s, Collection<String> contains)
s
- scontains
- containsCopyright © 2024. All rights reserved.