java.lang.Object
org.seppiko.commons.utils.StringUtil
String Util
- Author:
- Leonard Woo
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic CharBuffercharsetDecode(Charset charset, byte[] data) Charset decodestatic byte[]charsetEncode(Charset charset, CharBuffer data) Charset encodestatic 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 booleantest string has any charstatic booleanhasText(CharSequence str) test char sequence has any char without non-blank characterstatic StringinitialsUpperCase(String str) Capitalize the first letterstatic booleanisDecimal(CharSequence input) Test CharSequence is decimalstatic booleanisEmpty(CharSequence str) test string is empty or contains only whitespace codepointsstatic booleanisInteger(CharSequence input) Test CharSequence is integerstatic booleanisNumeric(CharSequence input) Test CharSequence is numericstatic booleanisPunct(CharSequence input) Test CharSequence is punctstatic booleanisSymbol(CharSequence input) Test CharSequence is symbolstatic 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 StringreplaceIndex(CharSequence data, int start, int end, CharSequence replacement) Replace CharSequence between start and endstatic StringGet a string object with default valuestatic Stringtranscoding(String data, Charset oldEncoding, Charset newEncoding) Convert string data from old encoding to new encoding
-
Constructor Details
-
StringUtil
public StringUtil()
-
-
Method Details
-
safeNull
Get a string object with default value- Parameters:
src- string objectdefaultValue- default string object- Returns:
- result
-
isEmpty
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
-
isInteger
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 punct- Parameters:
input- punct- Returns:
- true is punct
-
isSymbol
Test CharSequence is symbol- Parameters:
input- symbol- Returns:
- true is symbol
-
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 or not the regular expression matches on the input, when the expression's syntax is invalid is null
-
transcoding
Convert string data from old encoding to new encoding- Parameters:
data- string dataoldEncoding- old encodingnewEncoding- new encoding- Returns:
- convert result
-
fixedLength
Return fixed length string object- Parameters:
str- string objectlength- count lengthpreChar- pre-padded character- Returns:
- fixed length string object
-
initialsUpperCase
Capitalize the first letter- Parameters:
str- origin string- Returns:
- new string
-
replaceIndex
Replace CharSequence between start and end- Parameters:
data- origin datastart- replace start indexend- replace end indexreplacement- replace data- Returns:
- new string
-
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
-
charsetDecode
Charset decode- Parameters:
charset- charset, e.g.StandardCharsets.UTF_8data- byte array- Returns:
- character buffer object
- See Also:
-
charsetEncode
Charset encode- Parameters:
charset- charset, e.g.StandardCharsets.UTF_8data- character buffer- Returns:
- byte array
- See Also:
-