public class StringKits extends Object
some copy from vipshop VJTools(com.vip.vjtools.vjkit.text.MoreStringUtil)
some copy from spring StringUtils
| 构造器和说明 |
|---|
StringKits() |
| 限定符和类型 | 方法和说明 |
|---|---|
static com.google.common.base.Splitter |
charsSplitter(String separatorChars)
使用多个可选的char作为分割符, 还可以设置omitEmptyStrings,trimResults等配置
设置后的Splitter进行重用,不要每次创建
|
static boolean |
endWith(CharSequence s,
char c)
判断字符串是否以字母结尾
如果字符串为Null或空,返回false
|
static String |
getReplaceAll(String input,
String regex,
String replacement)
Replace every subsequence of the input sequence that matches the
pattern with the given replacement string.
|
static String |
getReplaceFirst(String input,
String regex,
String replacement)
Replace the first subsequence of the input sequence that matches the
regex with the given replacement string.
|
static boolean |
hasLength(String str)
Check that the given
String is neither null nor of length 0. |
static boolean |
hasText(CharSequence str)
Check whether the given
CharSequence contains actual text. |
static boolean |
hasText(String str)
Check whether the given
String contains actual text. |
static String |
lowerCamelToLowerUnderscore(String input)
小写驼峰(lowerCamel) -> 小写下划线(lower_underscore)
|
static String |
lowerUnderscoreTolowerCamel(String input)
小写下划线(lower_underscore) -> 小写驼峰(lowerCamel)
|
static String |
lowerUnderscoreToUpperCamel(String input)
小写下划线(lower_underscore) -> 大写驼峰(UpperCamel)
|
static String |
placeholderFormat(String strPattern,
Object... argArray)
格式化字符串
此方法只是简单将占位符 {} 按照顺序替换为参数 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可 例: 通常使用: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 |
removeEnd(String s,
char c)
如果结尾字符为c, 去除掉该字符.
|
static String |
replaceFirst(String s,
char sub,
char with)
String 有replace(char,char),但缺少单独replace first/last的
|
static String |
replaceLast(String s,
char sub,
char with)
String 有replace(char,char)替换全部char,但缺少单独replace first/last
|
static List<String> |
split(String str,
char separatorChar)
高性能的Split,针对char的分隔符号,比JDK String自带的高效.
|
static List<String> |
split(String str,
char separatorChar,
int expectParts)
高性能的Split,针对char的分隔符号,比JDK String自带的高效.
|
static boolean |
startWith(CharSequence s,
char c)
判断字符串是否以字母开头
如果字符串为Null或空,返回false
|
static String |
trimAllWhitespace(String str)
Trim all whitespace from the given
String:
leading, trailing, and in between characters. |
static String |
upperCamelToLowerUnderscore(String input)
大写驼峰(UpperCamel)-> 小写下划线(lower_underscore)
|
static int |
utf8EncodedLength(CharSequence sequence)
计算字符串被UTF8编码后的字节数 via guava
|
public static List<String> split(String str, char separatorChar)
public static List<String> split(String str, char separatorChar, int expectParts)
expectParts - 预估分割后的List大小,初始化数据更精准public static com.google.common.base.Splitter charsSplitter(String separatorChars)
设置后的Splitter进行重用,不要每次创建
separatorChars - 比如Unix/Windows的路径分割符 "/\\"Splitterpublic static String replaceFirst(String s, char sub, char with)
public static String replaceLast(String s, char sub, char with)
public static boolean startWith(CharSequence s, char c)
如果字符串为Null或空,返回false
public static boolean endWith(CharSequence s, char c)
如果字符串为Null或空,返回false
public static int utf8EncodedLength(CharSequence sequence)
public static String lowerUnderscoreTolowerCamel(String input)
public static String lowerUnderscoreToUpperCamel(String input)
public static String lowerCamelToLowerUnderscore(String input)
public static String upperCamelToLowerUnderscore(String input)
public static String getReplaceFirst(String input, String regex, String replacement)
input - The input.regex - The regex.replacement - The replacement string.public static String getReplaceAll(String input, String regex, String replacement)
input - The input.regex - The regex.replacement - The replacement string.public static boolean hasLength(String str)
String is neither null nor of length 0.
Note: this method returns true for a String that
purely consists of whitespace.
str - the String to check (may be null)true if the String is not null and has lengthpublic static boolean hasText(CharSequence str)
CharSequence contains actual text.
More specifically, this method returns true if the
CharSequence is not null, its length is greater than
0, and it contains at least one non-whitespace character.
StringUtils.hasText(null) = false
StringUtils.hasText("") = false
StringUtils.hasText(" ") = false
StringUtils.hasText("12345") = true
StringUtils.hasText(" 12345 ") = true
str - the CharSequence to check (may be null)true if the CharSequence is not null,
its length is greater than 0, and it does not contain whitespace onlyCharacter.isWhitespace(char)public static boolean hasText(String str)
String contains actual text.
More specifically, this method returns true if the
String is not null, its length is greater than 0,
and it contains at least one non-whitespace character.
str - the String to check (may be null)true if the String is not null, its
length is greater than 0, and it does not contain whitespace onlyhasText(CharSequence)public static String trimAllWhitespace(String str)
String:
leading, trailing, and in between characters.str - the String to checkStringCharacter.isWhitespace(char)public static String placeholderFormat(String strPattern, Object... argArray)
strPattern - 字符串模板argArray - 参数列表Copyright © 2019. All rights reserved.