Class Strings
-
- All Implemented Interfaces:
public final class Strings
-
-
Field Summary
Fields Modifier and Type Field Description public final static Array<String>emptyStringArraypublic final static charCOMMApublic final static StringCOMMA_STRpublic final static charFULL_WIDTH_COMMApublic final static StringFULL_WIDTH_COMMA_STRpublic final static charESCAPE_CHARpublic final static PatternHTML_CHARSET_PATTERNpublic final static PatternPRICE_PATTERNpublic final static StringDEFAULT_KEEP_CHARSpublic final static StringHTML_TAG_REGEXpublic final static StringFLOAT_REGEXpublic static PatternFLOAT_PATTERNpublic static PatternHTML_TAG_PATTERNpublic final static StringNUMERIC_LIKE_REGEXpublic static PatternNUMERIC_LIKE_PATTERNpublic final static StringMONEY_LIKE_REGEXpublic static PatternMONEY_LIKE_PATTERNpublic final static StringCHINESE_PHONE_NUMBER_LIKE_REGEXpublic static PatternCHINESE_PHONE_NUMBER_LIKE_PATTERNpublic final static StringIP_PORT_REGEXpublic final static PatternIP_PORT_PATTERNpublic final static intCODE_KEYBOARD_WHITESPACEpublic final static intCODE_NBSPpublic final static StringKEYBOARD_WHITESPACEpublic final static StringNBSPpublic final static Array<char>HEX_DIGITSpublic final static Array<String>paddingpublic final static Comparator<String>LongerFirstComparatorpublic final static Comparator<String>ShorterFirstComparatorpublic final static PatternPatternTime
-
Constructor Summary
Constructors Constructor Description Strings()
-
Method Summary
Modifier and Type Method Description static intcountTimeString(String text)static booleanisActuallyWhitespace(int c)Tests if a code point is "whitespace" as defined by what it looks like. static StringtoHexString(ByteBuffer buf)Convenience call for toHexString, where sep = null; lineLen = Integer.MAX_VALUE.static StringtoHexString(ByteBuffer buf, String sep, int lineLen)Get a text representation of a ByteBuffer as hexadecimal String, where each pair of hexadecimal digits corresponds to consecutive bytes in the array. static StringtoHexString(Array<byte> buf)Convenience call for toHexString, where sep = null; lineLen = Integer.MAX_VALUE.static StringtoHexString(Array<byte> buf, String sep, int lineLen)Get a text representation of a byte[] as hexadecimal String, where each pair of hexadecimal digits corresponds to consecutive bytes in the array. static StringtoHexString(Array<byte> buf, int of, int cb, String sep, int lineLen)Get a text representation of a byte[] as hexadecimal String, where each pair of hexadecimal digits corresponds to consecutive bytes in the array. static booleanisChinese(char c)static booleanisChinese(String text)static booleanisMainlyChinese(String text, double percentage)static intcountChinese(String text)static booleanisChineseByREG(String str)static booleanisChineseCharByREG(char ch)static booleanisChineseByName(String str)static StringremoveNonChar(String text)static StringstripNonChar(String text)static StringstripNonChar(String text, String keeps)static StringremoveNonChar(String text, String keeps)static StringtrimNonChar(String text)static StringtrimNonChar(String text, String keeps)// 对字符串的头部和尾部: // 1. static booleanisCJK(char ch)static StringremoveNonCJKChar(String text)对整个字符串: 1. static StringremoveNonCJKChar(String text, String keeps)static StringtrimNonCJKChar(String text)static StringtrimNonCJKChar(String text, String keeps)对字符串的头部和尾部: 1. static StringremoveNonPrintableChar(String s)Strip non-printable characters from a string. static StringstripNonPrintableChar1(String s)static booleanisPrintableUnicodeChar(char ch)static StringremoveControlChars(String input)static StringclearControlChars(String input)static StringclearControlChars(String input, String replacement)static StringgetLongestPart(String text, Pattern pattern)static StringgetLongestPart(String text, String regex)static Stringcsslize(String text)See CaseFormat from Guava, for example, LOWER_UNDERSCORE. static Stringhumanize(String text)See CaseFormat from Guava, for example, LOWER_UNDERSCORE. static Stringhumanize(String text, String seperator)See CaseFormat from Guava, for example, LOWER_UNDERSCORE. static Stringhumanize(String text, String suffix, String seperator)See CaseFormat from Guava, for example, LOWER_UNDERSCORE. static Stringhumanize(Class clazz, String suffix, String seperator)See CaseFormat from Guava, for example, LOWER_UNDERSCORE. static intgetLeadingInteger(String s, int defaultValue)static intgetTailingInteger(String s, int defaultValue)static intgetFirstInteger(String s, int defaultValue)static IntegergetFirstInteger(String s)static IntegerfindFirstInteger(String s)Find the first integer in the string. static intfindFirstInteger(String s, int defaultValue)static intgetLastInteger(String s, int defaultValue)static IntegerfindLastInteger(String s)Find the last integer in the string. static intfindLastInteger(String s, int defaultValue)static floatgetFirstFloatNumber(String s, float defaultValue)static floatfindLastFloatNumber(String s, float defaultValue)static booleancontains(String text, Array<CharSequence> searchCharSequences)static booleancontainsAny(String text, Array<CharSequence> searchCharSequences)static booleancontainsNone(String text, Array<CharSequence> searchCharSequences)static Stringreverse(String s)static StringdoubleQuoteIfContainsWhitespace(String s)static StringcompactFormat(int number)Formats a decimal number in its compact, readable form. static StringcompactFormat(long number)Formats a decimal number in its compact, readable form. static StringcompactFormat(int number, boolean si)Formats a decimal number in its compact, readable form. static StringcompactFormat(long number, boolean si)Formats a decimal number in its compact, readable form. static StringcompactFormat(int number, int scale, boolean si)Formats a decimal number in its compact, readable form. static StringcompactFormat(long number, int scale, boolean si)Formats a decimal number in its compact, readable form. static Map<String, String>parseKvs(String line)Parse key-value pairs in a line, for example : "a=1 b=2 c=3", "x:1 y:2 z:3" static Map<String, String>parseKvs(String line, String delimiter)Parse key-value pairs in a line, for example : "a=1 b=2 c=3", "x:1 y:2 z:3" static List<String>getUnslashedLines(String allLines)All lines separated by backslashes are merged together static List<String>getUnslashedLines(String allLines, String EOL)getUnslashedLines. static StringmergeSlashedLine(String slashedLine)Merge lines concatenated with backslash, for example : The line "Java Stream API is very, very useful, \\\n" " and we use them everywhere " can be merged into "Java Stream API is very, very useful, and we use them everywhere" static List<String>mergeSlashedLines(Iterable<String> linesWithSlash)All lines separated by backslashes are merged together static intgetLongestCommonSubstring(String a, String b)static StringreplaceCharsetInHtml(String html, String charset)static Array<String>getStrings(String str)static StringarrayToString(Array<String> strs)static Collection<String>getStringCollection(String str)static Collection<String>getStringCollection(String str, String delim)static Collection<String>getTrimmedStringCollection(String str)Splits a comma separated value String, trimming leading and trailing whitespace on each value.static Array<String>getTrimmedStrings(String str)Splits a comma separated value String, trimming leading and trailing whitespace on each value.static booleanhasHTMLTags(String text)static booleanisFloat(String text)static booleanisNumericLike(String text)static booleanisMoneyLike(String text)regextester static booleanisIpPortLike(String text)isIpPortLike. static booleanisIpLike(String text)isIpLike. static booleanisIpV4Like(String text)-
-
Method Detail
-
countTimeString
static int countTimeString(String text)
-
isActuallyWhitespace
static boolean isActuallyWhitespace(int c)
Tests if a code point is "whitespace" as defined by what it looks like. Used for Element.text etc.
- Parameters:
c- code point to test- Returns:
true if code point is whitespace, false otherwise
-
toHexString
static String toHexString(ByteBuffer buf)
Convenience call for toHexString, where
sep = null; lineLen = Integer.MAX_VALUE.- Parameters:
buf- The byte buffer- Returns:
The hex string
-
toHexString
static String toHexString(ByteBuffer buf, String sep, int lineLen)
Get a text representation of a ByteBuffer as hexadecimal String, where each pair of hexadecimal digits corresponds to consecutive bytes in the array.
- Parameters:
buf- input datasep- separate every pair of hexadecimal digits with this separator, or null if no separation is needed.lineLen- break the output String into lines containing output for lineLen bytes.- Returns:
The hex string
-
toHexString
static String toHexString(Array<byte> buf)
Convenience call for toHexString, where
sep = null; lineLen = Integer.MAX_VALUE.- Parameters:
buf- the buffer- Returns:
a java.lang.String object.
-
toHexString
static String toHexString(Array<byte> buf, String sep, int lineLen)
Get a text representation of a byte[] as hexadecimal String, where each pair of hexadecimal digits corresponds to consecutive bytes in the array.
- Parameters:
buf- input datasep- separate every pair of hexadecimal digits with this separator, or null if no separation is needed.lineLen- break the output String into lines containing output for lineLen bytes.- Returns:
a java.lang.String object.
-
toHexString
static String toHexString(Array<byte> buf, int of, int cb, String sep, int lineLen)
Get a text representation of a byte[] as hexadecimal String, where each pair of hexadecimal digits corresponds to consecutive bytes in the array.
- Parameters:
buf- input dataof- the offset into the byte[] to start readingcb- the number of bytes to read from the byte[]sep- separate every pair of hexadecimal digits with this separator, or null if no separation is needed.lineLen- break the output String into lines containing output for lineLen bytes.- Returns:
a java.lang.String object.
-
isChinese
static boolean isChinese(char c)
-
isMainlyChinese
static boolean isMainlyChinese(String text, double percentage)
-
countChinese
static int countChinese(String text)
-
isChineseByREG
static boolean isChineseByREG(String str)
-
isChineseCharByREG
static boolean isChineseCharByREG(char ch)
-
isChineseByName
static boolean isChineseByName(String str)
-
removeNonChar
static String removeNonChar(String text)
-
stripNonChar
static String stripNonChar(String text)
-
stripNonChar
static String stripNonChar(String text, String keeps)
-
removeNonChar
static String removeNonChar(String text, String keeps)
-
trimNonChar
static String trimNonChar(String text)
-
trimNonChar
static String trimNonChar(String text, String keeps)
// 对字符串的头部和尾部: // 1. 仅保留英文字符、数字、汉字字符和keeps中的字符 // 2. 去除网页空白:
-
isCJK
static boolean isCJK(char ch)
-
removeNonCJKChar
static String removeNonCJKChar(String text)
对整个字符串: 1. 仅保留英文字符、数字、汉字字符和 keeps 中的字符 2. 去除网页空白: String attrName = "配 送 至:京 东 价:当 当 价"; attrName = StringUtils.strip(attrName).replaceAll("[\\s+::( )]", ""); the "blank" characters in the above phrase can not be removed
-
removeNonCJKChar
static String removeNonCJKChar(String text, String keeps)
-
trimNonCJKChar
static String trimNonCJKChar(String text)
-
trimNonCJKChar
static String trimNonCJKChar(String text, String keeps)
对字符串的头部和尾部: 1. 仅保留英文字符、数字、汉字字符和keeps中的字符 2. 去除网页空白:
-
removeNonPrintableChar
static String removeNonPrintableChar(String s)
Strip non-printable characters from a string.
- Parameters:
s- the string to strip.- Returns:
a new string with non-printable characters removed.
-
stripNonPrintableChar1
static String stripNonPrintableChar1(String s)
-
isPrintableUnicodeChar
static boolean isPrintableUnicodeChar(char ch)
-
removeControlChars
static String removeControlChars(String input)
-
clearControlChars
static String clearControlChars(String input)
-
clearControlChars
static String clearControlChars(String input, String replacement)
-
getLongestPart
static String getLongestPart(String text, Pattern pattern)
-
getLongestPart
static String getLongestPart(String text, String regex)
-
csslize
static String csslize(String text)
See CaseFormat from Guava, for example, LOWER_UNDERSCORE.to(LOWER_CAMEL, str)
-
humanize
static String humanize(String text)
See CaseFormat from Guava, for example, LOWER_UNDERSCORE.to(LOWER_CAMEL, str)
-
humanize
static String humanize(String text, String seperator)
See CaseFormat from Guava, for example, LOWER_UNDERSCORE.to(LOWER_CAMEL, str)
-
humanize
static String humanize(String text, String suffix, String seperator)
See CaseFormat from Guava, for example, LOWER_UNDERSCORE.to(LOWER_CAMEL, str)
-
humanize
static String humanize(Class clazz, String suffix, String seperator)
See CaseFormat from Guava, for example, LOWER_UNDERSCORE.to(LOWER_CAMEL, str)
-
getLeadingInteger
static int getLeadingInteger(String s, int defaultValue)
-
getTailingInteger
static int getTailingInteger(String s, int defaultValue)
-
getFirstInteger
static int getFirstInteger(String s, int defaultValue)
-
getFirstInteger
static Integer getFirstInteger(String s)
-
findFirstInteger
static Integer findFirstInteger(String s)
Find the first integer in the string.
- Returns:
the first integer in the string, or null if not found
-
findFirstInteger
static int findFirstInteger(String s, int defaultValue)
-
getLastInteger
static int getLastInteger(String s, int defaultValue)
-
findLastInteger
static Integer findLastInteger(String s)
Find the last integer in the string.
- Returns:
the last integer in the string, or null if not found
-
findLastInteger
static int findLastInteger(String s, int defaultValue)
-
getFirstFloatNumber
static float getFirstFloatNumber(String s, float defaultValue)
-
findLastFloatNumber
static float findLastFloatNumber(String s, float defaultValue)
-
contains
static boolean contains(String text, Array<CharSequence> searchCharSequences)
-
containsAny
static boolean containsAny(String text, Array<CharSequence> searchCharSequences)
-
containsNone
static boolean containsNone(String text, Array<CharSequence> searchCharSequences)
-
reverse
@Deprecated() static String reverse(String s)
-
doubleQuoteIfContainsWhitespace
static String doubleQuoteIfContainsWhitespace(String s)
-
compactFormat
static String compactFormat(int number)
Formats a decimal number in its compact, readable form.
-
compactFormat
static String compactFormat(long number)
Formats a decimal number in its compact, readable form.
-
compactFormat
static String compactFormat(int number, boolean si)
Formats a decimal number in its compact, readable form.
-
compactFormat
static String compactFormat(long number, boolean si)
Formats a decimal number in its compact, readable form.
-
compactFormat
static String compactFormat(int number, int scale, boolean si)
Formats a decimal number in its compact, readable form.
-
compactFormat
static String compactFormat(long number, int scale, boolean si)
Formats a decimal number in its compact, readable form.
- Parameters:
number- the number to formatscale- the scale of the format resultsi- indicate if format to a SI unit The International System Of Units (SI) is the metric system that is used universally as a standard for measurements.- Returns:
The formatted number
-
parseKvs
static Map<String, String> parseKvs(String line)
Parse key-value pairs in a line, for example : "a=1 b=2 c=3", "x:1 y:2 z:3"
- Parameters:
line- The line to parse- Returns:
The parsed result
-
parseKvs
static Map<String, String> parseKvs(String line, String delimiter)
Parse key-value pairs in a line, for example : "a=1 b=2 c=3", "x:1 y:2 z:3"
- Parameters:
line- The line to parsedelimiter- a java.lang.String object.- Returns:
The parsed result
-
getUnslashedLines
static List<String> getUnslashedLines(String allLines)
All lines separated by backslashes are merged together
- Parameters:
allLines- All lines separated by "\n", some of them are separated by backslash- Returns:
All lines separated by backslashes are merged
-
getUnslashedLines
static List<String> getUnslashedLines(String allLines, String EOL)
getUnslashedLines.
- Parameters:
allLines- a java.lang.String object.EOL- a java.lang.String object.- Returns:
a java.util.List object.
-
mergeSlashedLine
static String mergeSlashedLine(String slashedLine)
Merge lines concatenated with backslash, for example : The line "Java Stream API is very, very useful, \\\n" " and we use them everywhere " can be merged into "Java Stream API is very, very useful, and we use them everywhere"
- Parameters:
slashedLine- a java.lang.String object.- Returns:
a java.lang.String object.
-
mergeSlashedLines
static List<String> mergeSlashedLines(Iterable<String> linesWithSlash)
All lines separated by backslashes are merged together
- Parameters:
linesWithSlash- Lines with backslash- Returns:
All lines separated by backslashes are merged
-
getLongestCommonSubstring
@Deprecated(forRemoval = true) static int getLongestCommonSubstring(String a, String b)
-
replaceCharsetInHtml
static String replaceCharsetInHtml(String html, String charset)
-
getStrings
static Array<String> getStrings(String str)
-
arrayToString
static String arrayToString(Array<String> strs)
-
getStringCollection
static Collection<String> getStringCollection(String str)
-
getStringCollection
static Collection<String> getStringCollection(String str, String delim)
-
getTrimmedStringCollection
static Collection<String> getTrimmedStringCollection(String str)
Splits a comma separated value
String, trimming leading and trailing whitespace on each value. Duplicate and empty values are removed.- Parameters:
str- a comma separated string with values- Returns:
a
CollectionofStringvalues
-
getTrimmedStrings
static Array<String> getTrimmedStrings(String str)
Splits a comma separated value
String, trimming leading and trailing whitespace on each value.- Parameters:
str- a comma separated String with values- Returns:
an array of
Stringvalues
-
hasHTMLTags
static boolean hasHTMLTags(String text)
-
isNumericLike
static boolean isNumericLike(String text)
-
isMoneyLike
static boolean isMoneyLike(String text)
- Parameters:
text- a String object.- Returns:
a boolean.
-
isIpPortLike
static boolean isIpPortLike(String text)
isIpPortLike.
- Parameters:
text- a java.lang.String object.- Returns:
a boolean.
-
isIpLike
static boolean isIpLike(String text)
isIpLike.
- Parameters:
text- a java.lang.String object.- Returns:
a boolean.
-
isIpV4Like
static boolean isIpV4Like(String text)
-
-
-
-