public abstract class StringUtils extends Object
| 构造器和说明 |
|---|
StringUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
camelCaseToUnderLineCase(String str)
把驼峰风格的字符串转换为下划线风格,连续的下划线会被替换为一个。
|
static String |
convertReturnToSpace(String str)
将换行符替换为空格
|
static String |
convertToLF(String str)
将CRLF和CR换行符转换为LF换行符
|
static String |
earseMultiSpcases(String str)
将制表符和多个连续的空格用一个空格替代
|
static String |
earseReturn(String str)
删除换行符
|
static boolean |
hasLength(CharSequence str)
Check that the given
CharSequence is neither null nor
of length 0. |
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 boolean |
isEmpty(Object str)
Check whether the given
String is empty. |
static boolean |
isNull(String str)
Check whether the given
String is empty or string "null". |
static String |
randomString(int length)
随机生成字符串,字符串可能的取值在ASCII 0x21-0x7e之间
|
static String |
subStringByBytes(String str,
int subBytes,
String suffix)
按字节长度截取字符串
|
static String |
toLowerCamelCase(String str) |
static String |
toLowerCaseFirstChar(String str)
首字母转小写
|
static String |
toPinYinString(String str)
将字符串转换为拼音
|
static String |
toUnderlineNomenclature(String str)
将字符串转为下划线命名法,连续的空白字符会被转换为一个下划线表示
|
static String |
toUpperCamelCase(String str) |
static String |
toUpperCaseFirstChar(String str)
首字母转大写
|
static String |
trim(String string)
去除字符串头尾的空白,与
String.trim()的区别在于可以处理空对象 |
public static String trim(String string)
String.trim()的区别在于可以处理空对象string - 待处理的字符串public static final boolean isNull(String str)
String is empty or string "null".str - the candidate Stringtrue if the str is null, "" or "null"public static boolean isEmpty(Object str)
String is empty.
This method accepts any Object as an argument, comparing it to
null and the empty String. As a consequence, this method
will never return true for a non-null non-String object.
The Object signature is useful for general attribute handling code that commonly deals with Strings but generally has to iterate over Objects since attributes may e.g. be primitive value objects as well.
str - the candidate Stringtrue if the str is null or ""public static boolean hasLength(CharSequence str)
CharSequence is neither null nor
of length 0.
Note: this method returns true for a CharSequence
that purely consists of whitespace.
StringUtils.hasLength(null) = false
StringUtils.hasLength("") = false
StringUtils.hasLength(" ") = true
StringUtils.hasLength("Hello") = true
str - the CharSequence to check (may be null)true if the CharSequence is not null and has lengthhasText(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 lengthhasLength(CharSequence),
hasText(String)public 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 subStringByBytes(String str, int subBytes, String suffix)
str - 要截取的字符串subBytes - 截取字节长度suffix - 如果发生截取,在结果后添加的后缀,为null表示不添加public static String earseMultiSpcases(String str)
str - 待处理的字符串public static String convertToLF(String str)
str - 待处理的字符串public static String convertReturnToSpace(String str)
str - 待处理的字符串public static String toUnderlineNomenclature(String str)
str - 待转换的字符串public static String camelCaseToUnderLineCase(String str)
StringUtils.camelCaseToUnderLineCase("EulerFramework") = "euler_framework"
StringUtils.camelCaseToUnderLineCase("Euler_Framework") = "euler_framework"
StringUtils.camelCaseToUnderLineCase("Euler__Framework") = "euler_framework"
StringUtils.camelCaseToUnderLineCase("Euler_framework") = "euler_framework"
StringUtils.camelCaseToUnderLineCase("eulerFramework") = "euler_framework"
str - 峰风格的字符串public static String toLowerCaseFirstChar(String str)
str - 待转换的字符串public static String toUpperCaseFirstChar(String str)
str - 待转换的字符串public static String randomString(int length)
length - 生成的字符串长度Copyright © 2017. All rights reserved.