public class StringUtil
extends org.apache.commons.lang3.StringUtils
| 限定符和类型 | 字段和说明 |
|---|---|
static String[] |
EMPTY_STRING_ARRAY |
| 构造器和说明 |
|---|
StringUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
abbr(String str,
int length)
缩略字符串(不区分中英文字符)
|
static String |
abbr2(String param,
int length) |
static void |
assertNotEmpty(Collection<?> c,
String message)
Check whether the collection is null or empty.
|
static void |
assertNotNull(Object object,
String message)
Check whether the object is null or not.
|
static void |
assertTrue(boolean cond,
String message)
Assert that the statement is true, otherwise throw an exception with the
provided message.
|
static boolean |
contains(CharSequence seq,
CharSequence searchSeq)
功能描述: 判断是否包含指定字符串
|
static int |
countOccurrencesOf(String str,
String sub)
Count the occurrences of the substring in string s.
|
static String |
decodeBase64(String str)
对字符串进行Base64解密,默认使用UTF-8编码
|
static String |
decodeBase64(String str,
String encoding)
使用指定的编码进行Base64解密
|
static String |
encodeBase64(String str)
对字符串进行Base64加密,默认使用UTF-8编码
|
static String |
encodeBase64(String str,
String encoding)
使用给定的编码对字符串进行Base64加密
|
static byte[] |
getBytes(String str)
转换为字节数组
|
static byte[] |
getBytesGBK(String string) |
static byte[] |
getBytesIso8859_1(String string)
Encodes the given string into a sequence of bytes using the ISO-8859-1 charset, storing the result into a new
byte array.
|
static byte[] |
getBytesUnchecked(String string,
String charsetName)
Encodes the given string into a sequence of bytes using the named charset, storing the result into a new byte
array.
|
static byte[] |
getBytesUsAscii(String string)
Encodes the given string into a sequence of bytes using the US-ASCII charset, storing the result into a new byte
array.
|
static byte[] |
getBytesUtf16(String string)
Encodes the given string into a sequence of bytes using the UTF-16 charset, storing the result into a new byte
array.
|
static byte[] |
getBytesUtf16Be(String string)
Encodes the given string into a sequence of bytes using the UTF-16BE charset, storing the result into a new byte
array.
|
static byte[] |
getBytesUtf16Le(String string)
Encodes the given string into a sequence of bytes using the UTF-16LE charset, storing the result into a new byte
array.
|
static byte[] |
getBytesUtf8(String string)
Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result into a new byte
array.
|
static String |
getRandomString2(int length)
功能描述: 随机字符串
|
static String |
getRemoteAddr(javax.servlet.http.HttpServletRequest request)
获得用户远程地址
|
static String |
getStarCenter(String content,
int frontNum,
int endNum)
对字符加星号处理:除前面几位和后面几位外,其他的字符以星号代替
|
static String |
getStarString(String content,
int begin,
int end)
对字符串处理:将指定位置到指定位置的字符以星号代替
|
static String |
getYCBBody(String str)
获取养车宝的bodyjson串
功能描述:
|
static boolean |
inString(String str,
String... strs)
是否包含字符串
|
static boolean |
isBlank(String string)
Determines if a String is blank or not.
|
static boolean |
isEmpty(String string)
Determines whether the String is null or of length 0.
|
static boolean |
isNotBlank(String string)
Determines if a string is not blank.
|
static boolean |
isNotEmpty(String string)
功能描述:
|
static String |
join(Collection collection,
char separator) |
static String |
join(Collection collection,
String separator) |
static String |
join(Iterator iterator,
char separator) |
static String |
join(Iterator iterator,
String separator) |
static String |
jsGetVal(String objectString)
转换为JS获取对象值,生成三目运算返回结果
|
static String |
newString(byte[] bytes,
String charsetName)
Constructs a new
String by decoding the specified array of bytes using the given charset. |
static String |
newStringIso8859_1(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the ISO-8859-1 charset. |
static String |
newStringUsAscii(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the US-ASCII charset. |
static String |
newStringUtf16(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the UTF-16 charset. |
static String |
newStringUtf16Be(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the UTF-16BE charset. |
static String |
newStringUtf16Le(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the UTF-16LE charset. |
static String |
newStringUtf8(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the UTF-8 charset. |
static String |
removeEnd(String str,
String remove) |
static String |
replaceHtml(String html)
替换掉HTML标签方法
|
static String |
replaceMobileHtml(String html)
替换为手机识别的HTML,去掉样式及属性,保留回车。
|
static void |
setValueIfNotBlank(String target,
String source)
如果不为空,则设置值
|
static String[] |
split(String str,
String separatorChars) |
static void |
state(boolean expression,
String message)
功能描述:
|
static String |
toCamelCase(String s)
驼峰命名法工具
|
static String |
toCapitalizeCamelCase(String s)
驼峰命名法工具
|
static Double |
toDouble(Object val)
转换为Double类型
|
static Float |
toFloat(Object val)
转换为Float类型
|
static String |
toHtml(String txt)
替换为手机识别的HTML,去掉样式及属性,保留回车。
|
static Integer |
toInteger(Object val)
转换为Integer类型
|
static String[] |
tokenizeToStringArray(String str,
String delimiters)
Tokenize the given String into a String array via a StringTokenizer.
|
static String[] |
tokenizeToStringArray(String str,
String delimiters,
boolean trimTokens,
boolean ignoreEmptyTokens)
Tokenize the given String into a String array via a StringTokenizer.
|
static Long |
toLong(Object val)
转换为Long类型
|
static String |
toString(byte[] bytes)
功能描述: 转换为字节数组
|
static String[] |
toStringArray(Collection<String> collection)
Copy the given Collection into a String array.
|
static String |
toUnderScoreCase(String s)
驼峰命名法工具
|
static String |
trimAllWhitespace(String str) |
abbreviate, abbreviate, abbreviateMiddle, appendIfMissing, appendIfMissingIgnoreCase, capitalize, center, center, center, chomp, chomp, chop, contains, containsAny, containsAny, containsIgnoreCase, containsNone, containsNone, containsOnly, containsOnly, containsWhitespace, countMatches, defaultIfBlank, defaultIfEmpty, defaultString, defaultString, deleteWhitespace, difference, endsWith, endsWithAny, endsWithIgnoreCase, equals, equalsIgnoreCase, getCommonPrefix, getJaroWinklerDistance, getLevenshteinDistance, getLevenshteinDistance, indexOf, indexOf, indexOf, indexOf, indexOfAny, indexOfAny, indexOfAny, indexOfAnyBut, indexOfAnyBut, indexOfDifference, indexOfDifference, indexOfIgnoreCase, indexOfIgnoreCase, isAllLowerCase, isAllUpperCase, isAlpha, isAlphanumeric, isAlphanumericSpace, isAlphaSpace, isAnyBlank, isAnyEmpty, isAsciiPrintable, isBlank, isEmpty, isNoneBlank, isNoneEmpty, isNotBlank, isNotEmpty, isNumeric, isNumericSpace, isWhitespace, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexOfAny, lastIndexOfIgnoreCase, lastIndexOfIgnoreCase, lastOrdinalIndexOf, left, leftPad, leftPad, leftPad, length, lowerCase, lowerCase, mid, normalizeSpace, ordinalIndexOf, overlay, prependIfMissing, prependIfMissingIgnoreCase, remove, remove, removeEndIgnoreCase, removePattern, removeStart, removeStartIgnoreCase, repeat, repeat, repeat, replace, replace, replaceChars, replaceChars, replaceEach, replaceEachRepeatedly, replaceOnce, replacePattern, reverse, reverseDelimited, right, rightPad, rightPad, rightPad, split, split, split, splitByCharacterType, splitByCharacterTypeCamelCase, splitByWholeSeparator, splitByWholeSeparator, splitByWholeSeparatorPreserveAllTokens, splitByWholeSeparatorPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, startsWith, startsWithAny, startsWithIgnoreCase, strip, strip, stripAccents, stripAll, stripAll, stripEnd, stripStart, stripToEmpty, stripToNull, substring, substring, substringAfter, substringAfterLast, substringBefore, substringBeforeLast, substringBetween, substringBetween, substringsBetween, swapCase, toEncodedString, toString, trim, trimToEmpty, trimToNull, uncapitalize, upperCase, upperCasepublic static final String[] EMPTY_STRING_ARRAY
public static void state(boolean expression,
String message)
expression - message - void
date: 2018年4月11日 下午4:58:01public static void assertNotNull(Object object, String message)
object - the object to check.message - the message to display if the object is null.public static void assertNotEmpty(Collection<?> c, String message)
c - the collecion to check.message - the message to display if the object is null.public static void assertTrue(boolean cond,
String message)
cond - the codition to assert is true.message - the message to display if the condition is not true.public static boolean isEmpty(String string)
string - the string to checkpublic static boolean isNotEmpty(String string)
string - public static boolean isBlank(String string)
string - the string to checkpublic static boolean isNotBlank(String string)
string - the string to check.public static String[] tokenizeToStringArray(String str, String delimiters)
The given delimiters string is supposed to consist of any number of
delimiter characters. Each of those characters can be used to separate
tokens. A delimiter is always a single character; for multi-character
delimiters, consider using delimitedListToStringArray
str - the String to tokenizedelimiters - the delimiter characters, assembled as String
(each of those characters is individually considered as delimiter).StringTokenizer,
String.trim()public static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens)
The given delimiters string is supposed to consist of any number of
delimiter characters. Each of those characters can be used to separate
tokens. A delimiter is always a single character; for multi-character
delimiters, consider using delimitedListToStringArray
str - the String to tokenizedelimiters - the delimiter characters, assembled as String
(each of those characters is individually considered as delimiter)trimTokens - trim the tokens via String's trimignoreEmptyTokens - omit empty tokens from the result array
(only applies to tokens that are empty after trimming; StringTokenizer
will not consider subsequent delimiters as token in the first place).null if the input String
was null)StringTokenizer,
String.trim()public static String[] toStringArray(Collection<String> collection)
collection - the Collection to copynull if the passed-in
Collection was null)public static int countOccurrencesOf(String str, String sub)
str - string to search in. Return 0 if this is null.sub - string to search for. Return 0 if this is null.public static boolean contains(CharSequence seq, CharSequence searchSeq)
seq - 字符串searchSeq - 被查找的字符串public static String join(Collection collection, String separator)
public static String join(Collection collection, char separator)
public static String encodeBase64(String str, String encoding)
str - 要加密的字符串encoding - 指定编码public static String encodeBase64(String str)
str - 要加密的字符串public static String decodeBase64(String str, String encoding)
str - 要解密的字符串encoding - 指定编码public static String decodeBase64(String str)
str - 要解密的字符串public static String getRandomString2(int length)
length - public static byte[] getBytes(String str)
str - public static String toString(byte[] bytes)
bytes - public static boolean inString(String str, String... strs)
str - 验证字符串strs - 字符串组public static String replaceMobileHtml(String html)
html - public static String abbr(String str, int length)
str - 目标字符串length - 截取长度public static String getRemoteAddr(javax.servlet.http.HttpServletRequest request)
public static String toCamelCase(String s)
public static String toCapitalizeCamelCase(String s)
public static String toUnderScoreCase(String s)
public static void setValueIfNotBlank(String target, String source)
target - source - public static String jsGetVal(String objectString)
objectString - 对象串
例如:row.user.id
返回:!row?'':!row.user?'':!row.user.id?'':row.user.idpublic static String getStarString(String content, int begin, int end)
content - 传入的字符串begin - 开始位置end - 结束位置public static String getStarCenter(String content, int frontNum, int endNum)
content - 传入的字符串frontNum - 保留前面字符的位数endNum - 保留后面字符的位数public static byte[] getBytesIso8859_1(String string)
string - the String to encode, may be nullnull if the input string was nullIllegalStateException - Thrown when the charset is missing, which should be never according the the Java specification.getBytesUnchecked(String, String)public static byte[] getBytesUsAscii(String string)
string - the String to encode, may be nullnull if the input string was nullIllegalStateException - Thrown when the charset is missing, which should be never according the the Java specification.getBytesUnchecked(String, String)public static byte[] getBytesUtf16(String string)
string - the String to encode, may be nullnull if the input string was nullIllegalStateException - Thrown when the charset is missing, which should be never according the the Java specification.getBytesUnchecked(String, String)public static byte[] getBytesUtf16Be(String string)
string - the String to encode, may be nullnull if the input string was nullIllegalStateException - Thrown when the charset is missing, which should be never according the the Java specification.getBytesUnchecked(String, String)public static byte[] getBytesUtf16Le(String string)
string - the String to encode, may be nullnull if the input string was nullIllegalStateException - Thrown when the charset is missing, which should be never according the the Java specification.getBytesUnchecked(String, String)public static byte[] getBytesUtf8(String string)
string - the String to encode, may be nullnull if the input string was nullIllegalStateException - Thrown when the charset is missing, which should be never according the the Java specification.getBytesUnchecked(String, String)public static byte[] getBytesGBK(String string)
public static byte[] getBytesUnchecked(String string, String charsetName)
This method catches UnsupportedEncodingException and rethrows it as IllegalStateException, which
should never happen for a required charset name. Use this method when the encoding is required to be in the JRE.
string - the String to encode, may be nullcharsetName - The name of a required Charsetnull if the input string was nullIllegalStateException - Thrown when a UnsupportedEncodingException is caught, which should never happen for a
required charset name.CharEncoding,
String.getBytes(String)public static String newString(byte[] bytes, String charsetName)
String by decoding the specified array of bytes using the given charset.
This method catches UnsupportedEncodingException and re-throws it as IllegalStateException, which
should never happen for a required charset name. Use this method when the encoding is required to be in the JRE.
bytes - The bytes to be decoded into characters, may be nullcharsetName - The name of a required CharsetString decoded from the specified array of bytes using the given charset,
or null if the input byte array was null.IllegalStateException - Thrown when a UnsupportedEncodingException is caught, which should never happen for a
required charset name.CharEncoding,
String.String(byte[], String)public static String newStringIso8859_1(byte[] bytes)
String by decoding the specified array of bytes using the ISO-8859-1 charset.bytes - The bytes to be decoded into characters, may be nullString decoded from the specified array of bytes using the ISO-8859-1 charset,
or null if the input byte array was null.IllegalStateException - Thrown when a UnsupportedEncodingException is caught, which should never happen since the
charset is required.public static String newStringUsAscii(byte[] bytes)
String by decoding the specified array of bytes using the US-ASCII charset.bytes - The bytes to be decoded into charactersString decoded from the specified array of bytes using the US-ASCII charset,
or null if the input byte array was null.IllegalStateException - Thrown when a UnsupportedEncodingException is caught, which should never happen since the
charset is required.public static String newStringUtf16(byte[] bytes)
String by decoding the specified array of bytes using the UTF-16 charset.bytes - The bytes to be decoded into charactersString decoded from the specified array of bytes using the UTF-16 charset
or null if the input byte array was null.IllegalStateException - Thrown when a UnsupportedEncodingException is caught, which should never happen since the
charset is required.public static String newStringUtf16Be(byte[] bytes)
String by decoding the specified array of bytes using the UTF-16BE charset.bytes - The bytes to be decoded into charactersString decoded from the specified array of bytes using the UTF-16BE charset,
or null if the input byte array was null.IllegalStateException - Thrown when a UnsupportedEncodingException is caught, which should never happen since the
charset is required.public static String newStringUtf16Le(byte[] bytes)
String by decoding the specified array of bytes using the UTF-16LE charset.bytes - The bytes to be decoded into charactersString decoded from the specified array of bytes using the UTF-16LE charset,
or null if the input byte array was null.IllegalStateException - Thrown when a UnsupportedEncodingException is caught, which should never happen since the
charset is required.public static String newStringUtf8(byte[] bytes)
String by decoding the specified array of bytes using the UTF-8 charset.bytes - The bytes to be decoded into charactersString decoded from the specified array of bytes using the UTF-8 charset,
or null if the input byte array was null.IllegalStateException - Thrown when a UnsupportedEncodingException is caught, which should never happen since the
charset is required.Copyright © 2018. All rights reserved.