public class Strings extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static char |
BLANK_CHAR |
| 构造器和说明 |
|---|
Strings() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
camelCaseName(String underscoreName)
已过时。
instead of CaseFormat#to(CaseFormat, String)
|
static String |
cleanPath(String path)
文件路径规范化,如“path/..”内部的点号
注意:windows的文件分隔符“\”会替换为“/”
|
static int |
count(String text,
String str)
Count str occur on text.
|
static List<String> |
csvSplit(List<String> list,
String s,
int off,
int len)
Split a quoted comma separated string to a list
Handle rfc4180-like
CSV strings, with the exceptions:
quoted values may contain double quotes escaped with back-slash
Non-quoted values are trimmed of leading trailing white space
trailing commas are ignored
double commas result in a empty string value
|
static String[] |
csvSplit(String s)
Parse a CSV string using
csvSplit(List,String, int, int)
use in {@link cn.ponfee.commons.web.WebContext.WebContextFilter) |
static String[] |
csvSplit(String s,
int off,
int len)
Parse a CSV string using
csvSplit(List, String, int, int) |
static String |
escapeRegex(String text)
Escape the regex characters: $()*+.[]?
|
static String |
escapeSql(String str)
Escapes the characters in a
String to be suitable to pass to
an SQL query. |
static Map<String,String> |
fromArgs(String[] args)
Parse main method args, such as: [name1=value,name2=value2,...]
|
static String[] |
hexadecimal(String text)
Convert to hexadecimal string array
|
static String |
ifBlank(String str,
String defaultStr) |
static String |
ifEmpty(String str,
String defaultStr)
如果为空则设置默认
|
static boolean |
isBlank(Object value) |
static boolean |
isEmpty(Object value)
判断是否为空字符串
|
static boolean |
isMatch(String s,
String p)
'?'
|
static String |
join(Collection<?> coll) |
static String |
join(Collection<?> coll,
String delimiter) |
static <T> String |
join(Collection<T> coll,
String delimiter,
Function<T,String> mapper,
String open,
String close)
集合拼接为字符串
join(Arrays.asList("a","b","c"), ",", "(", ")") -> (a),(b),(c)
|
static String |
mask(String text,
int start,
int len) |
static String |
mask(String text,
int start,
int len,
char maskChar)
遮掩(如手机号中间4位加*)
|
static String |
mask(String text,
String regex,
String replacement) |
static String |
safePath(String path)
Returns a safe file system path that forbid access parent dir
|
static String[] |
slice(String str,
int segment)
字符串分片
slice("abcdefghijklmn", 5) -> ["abc","def","ghi","jkl","mn"]
|
static String |
underscoreName(String camelCaseName)
已过时。
instead of CaseFormat#to(CaseFormat, String)
|
public static final char BLANK_CHAR
public static String join(Collection<?> coll)
public static String join(Collection<?> coll, String delimiter)
public static String[] hexadecimal(String text)
text - the textpublic static <T> String join(Collection<T> coll, String delimiter, Function<T,String> mapper, String open, String close)
join(Arrays.asList("a","b","c"), ",", "(", ")") -> (a),(b),(c)
coll - 集合对象delimiter - 分隔符mapper - 对象转Stringopen - 每个元素添加的前缀close - 每个元素添加的后缀IteratorUtils.toString(Iterator, org.apache.commons.collections4.Transformer, String, String, String),
IterableUtils.toString(Iterable, org.apache.commons.collections4.Transformer, String, String, String),
String.join(CharSequence, CharSequence...),
Collectors.joining(CharSequence, CharSequence, CharSequence),
StringUtils.join(List, String, int, int),
Joiner.join(Object, Object, Object...),
StringJoiner(CharSequence, CharSequence, CharSequence)public static Map<String,String> fromArgs(String[] args)
args - the argspublic static String mask(String text, int start, int len, char maskChar)
text - 需要处理的字符串start - 开始位置len - 要处理的字数长度maskChar - 替换的字符public static int count(String text, String str)
text - the textstr - the stringpublic static String[] slice(String str, int segment)
str - segment - public static boolean isMatch(String s, String p)
s - charactersp - patternpublic static String safePath(String path)
path - the pathpublic static String cleanPath(String path)
path - 文件路径@Deprecated public static String underscoreName(String camelCaseName)
camelCaseName - 驼峰名CaseFormat.to(CaseFormat, String)@Deprecated public static String camelCaseName(String underscoreName)
underscoreName - 下划线名CaseFormat.to(CaseFormat, String)public static boolean isEmpty(Object value)
value - public static boolean isBlank(Object value)
public static String ifEmpty(String str, String defaultStr)
str - defaultStr - public static String escapeSql(String str)
Escapes the characters in aStringto be suitable to pass to an SQL query. For example, statement.executeQuery("SELECT * FROM MOVIES WHERE TITLE='" + StringEscapeUtils.escapeSql("McHale's Navy") + "'"); At present, this method only turns single-quotes into doubled single-quotes ("McHale's Navy"=>"McHale''s Navy"). It does not handle the cases of percent (%) or underscore (_) for use in LIKE clauses. see http://www.jguru.com/faq/view.jsp?EID=8881
str - the string to escape, may be nullnull if null string inputpublic static String escapeRegex(String text)
text - the text stringpublic static String[] csvSplit(String s)
csvSplit(List,String, int, int)
use in {@link cn.ponfee.commons.web.WebContext.WebContextFilter)s - The string to parsepublic static String[] csvSplit(String s, int off, int len)
csvSplit(List, String, int, int)s - The string to parseoff - The offset into the string to start parsinglen - The len in characters to parsepublic static List<String> csvSplit(List<String> list, String s, int off, int len)
Handle rfc4180-like CSV strings, with the exceptions:
list - The Collection to split to (or null to get a new list)s - The string to parseoff - The offset into the string to start parsinglen - The len in characters to parseCopyright © 2023. All rights reserved.