java.lang.Object
org.seppiko.commons.utils.StringUtil
String Util
- Author:
- Leonard Woo
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringconvertJoinerString(String delimiter, String... strs) convert joiner string with delimiterstatic char[]convertToCharArray(String src, String split) Delete string Separator and to char arraystatic StringconvertToString(char[] src, int splitNum, String split) Convert char array to String with separatestatic StringfixedLength(String str, int length, char preChar) Return fixed length string objectstatic MatchergetMatcher(String regex, CharSequence input) Compiles the given regular expression the given input against it.static booleanhasLength(CharSequence str) test string has any charstatic booleanhasText(CharSequence str) test char sequence has any char without non-blank characterstatic booleanisDecimal(CharSequence input) Test CharSequence is decimalstatic booleanisDigit(CharSequence input) Test CharSequence is integerstatic booleantest string is empty or contains only whitespace codepointsstatic booleanisNumeric(CharSequence input) Test CharSequence is numericstatic booleanisPunct(CharSequence input) Test CharSequence is Punctuationstatic Booleanmatches(String regex, CharSequence input) Compiles the given regular expression and attempts to match the given input against it.static booleannonText(CharSequence str) test char sequence is not null and empty or has non-blank characterstatic StringreplaceBetween(CharSequence data, int start, int end, CharSequence replacement) Replace CharSequence between start and endstatic CharSequencerequireNonBlankElse(CharSequence str, CharSequence defaultStr) Require a string with default valuestatic StringtoFirstUpperCase(String input) Capitalize the first letterstatic StringtoFullWidth(CharSequence src) convert half-width to full-widthstatic StringtoHalfWidth(CharSequence src) convert full-width to half-widthstatic Stringtranscoding(CharSequence data, Charset oldEncoding, Charset newEncoding) Convert string data from old encoding to new encodingstatic StringunicodeDecode(String src) Unicode decoding When not found return origin Stringstatic StringunicodeEncode(String src) Unicode encoding
-
Method Details
-
requireNonBlankElse
Require a string with default value- Parameters:
str- stringdefaultStr- default string- Returns:
- result
-
isNullOrEmpty
test string is empty or contains only whitespace codepoints- Parameters:
str- string object- Returns:
- true is yes
-
hasLength
test string has any char- Parameters:
str- string object- Returns:
- true is yes
-
hasText
test char sequence has any char without non-blank character- Parameters:
str- char sequence object- Returns:
- true is not null and without whitespace
-
nonText
test char sequence is not null and empty or has non-blank character- Parameters:
str- char sequence object- Returns:
- true is not null and empty
-
isNumeric
Test CharSequence is numeric- Parameters:
input- numeric- Returns:
- true is numeric
-
isDigit
Test CharSequence is integer- Parameters:
input- numeric- Returns:
- true is integer
-
isDecimal
Test CharSequence is decimal- Parameters:
input- numeric- Returns:
- true is decimal
-
isPunct
Test CharSequence is Punctuation- Parameters:
input- punct- Returns:
- true is punct
-
matches
Compiles the given regular expression and attempts to match the given input against it.- Parameters:
regex- The expression to be compiledinput- The character sequence to be matched- Returns:
- whether the regular expression matches on the input, when the expression's syntax is invalid is null
-
getMatcher
Compiles the given regular expression the given input against it.- Parameters:
regex- The expression to be compiledinput- The character sequence to be matched- Returns:
- Matcher object
-
transcoding
public static String transcoding(CharSequence data, Charset oldEncoding, Charset newEncoding) throws NullPointerException Convert string data from old encoding to new encoding- Parameters:
data- string dataoldEncoding- old encodingnewEncoding- new encoding- Returns:
- convert result
- Throws:
NullPointerException- old encode or new decode exception
-
fixedLength
Return fixed length string object- Parameters:
str- string objectlength- count lengthpreChar- pre-padded character- Returns:
- fixed length string object
-
toFirstUpperCase
Capitalize the first letter- Parameters:
input- origin string- Returns:
- new string
-
replaceBetween
public static String replaceBetween(CharSequence data, int start, int end, CharSequence replacement) Replace CharSequence between start and end- Parameters:
data- origin datastart- replace start indexend- replace end indexreplacement- replace data- Returns:
- new string
-
convertJoinerString
convert joiner string with delimiter- Parameters:
delimiter- the sequence of characters to be used between each array elementstrs- string element- Returns:
- the string representation
-
convertToString
Convert char array to String with separate- Parameters:
src- Raw datasplitNum- Separation intervalsplit- Separator- Returns:
- encoded string
-
convertToCharArray
Delete string Separator and to char array- Parameters:
src- Datasplit- Separator- Returns:
- char array
- Throws:
NullPointerException- when data or separator is null
-
toFullWidth
convert half-width to full-width- Parameters:
src- Half-width String- Returns:
- Full-width String
-
toHalfWidth
convert full-width to half-width- Parameters:
src- Full-width String- Returns:
- Half-width String
-
unicodeDecode
Unicode decoding When not found return origin String- Parameters:
src- unicode- Returns:
- String
-
unicodeEncode
Unicode encoding- Parameters:
src- String- Returns:
- unicode
-