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 array.static StringconvertToString(char[] src, int splitNum, String split) Convert char array to String with separatestatic Stringfind(String regex, CharSequence input) Returns the input subsequence captured by the given index during match operation.static 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 CharSequence has any charstatic booleanhasText(CharSequence str) Test CharSequence has any char without non-blank characterstatic booleanisDecimal(CharSequence input) Test CharSequence is decimalstatic booleanisDigit(CharSequence input) Test CharSequence is integerstatic booleanisNullOrEmpty(CharSequence value) Test CharSequence is empty or contains only whitespace codepointsstatic booleanisNumeric(CharSequence input) Test CharSequence is numericstatic booleanisPunctuation(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 CharSequence 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 value, CharSequence defaultValue) Require a CharSequence with default value.static StringtoFirstUpperCase(String input) Capitalize the first letterstatic StringtoFullWidth(CharSequence src) Convert half-width string ('\u0021'through'\u007E') to full-width string ('\uFF01'through'\uFF5E')static StringtoHalfWidth(CharSequence src) Convert full-width string ('\uFF01'through'\uFF5E') to half-width string ('\u0021'through'\u007E')static 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 CharSequence with default value.- Parameters:
value- CharSequence instance.defaultValue- default CharSequence instance.- Returns:
- CharSequence without null.
-
isNullOrEmpty
Test CharSequence is empty or contains only whitespace codepoints- Parameters:
value- CharSequence instance.- Returns:
- true is yes.
-
hasLength
Test CharSequence has any char- Parameters:
str- CharSequence instance.- Returns:
- true is yes.
-
hasText
Test CharSequence has any char without non-blank character- Parameters:
str- CharSequence instance.- Returns:
- true is not null and without whitespace, false is otherwise.
-
nonText
Test CharSequence is not null and empty or has non-blank character- Parameters:
str- CharSequence instance.- Returns:
- true is not null and empty, false is otherwise.
-
isNumeric
Test CharSequence is numeric- Parameters:
input- numeric CharSequence.- Returns:
- true is numeric.
-
isDigit
Test CharSequence is integer- Parameters:
input- numeric CharSequence.- Returns:
- true is integer.
-
isDecimal
Test CharSequence is decimal- Parameters:
input- numeric CharSequence.- Returns:
- true is decimal.
-
isPunctuation
Test CharSequence is punctuation- Parameters:
input- punctuation CharSequence.- Returns:
- true is punctuation.
-
matches
Compiles the given regular expression and attempts to match the given input against it.- Parameters:
regex- The expression to be compiled.input- The character sequence to be matched.- Returns:
- Whether the regular expression matches on the input, when the expression syntax is
invalid is
null.
-
find
Returns the input subsequence captured by the given index during match operation.- Parameters:
regex- The expression to be compiled.input- The character sequence to be matched.- Returns:
- The (possibly empty) subsequence captured by the index during match, or empty if the group failed to match part of the input.
-
getMatcher
Compiles the given regular expression the given input against it.- Parameters:
regex- The expression to be compiled.input- The character sequence to be matched.- Returns:
Matcherinstance, if the expression's syntax is invalid returnnull.
-
transcoding
public static String transcoding(CharSequence data, Charset oldEncoding, Charset newEncoding) throws NullPointerException Convert string data from old encoding to new encoding- Parameters:
data- CharSequence data.oldEncoding- old encoding.newEncoding- new encoding.- Returns:
- new encoding CharSequence.
- Throws:
NullPointerException- old encode or new decode exception.
-
fixedLength
Return fixed length string object- Parameters:
str- string object.length- count length.preChar- 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 data.start- replace start index.end- replace end index.replacement- replace data.- Returns:
- new string.
-
convertJoinerString
convert joiner string with delimiter- Parameters:
delimiter- the sequence of characters to be used between each array element.strs- string array.- Returns:
- the string representation.
-
convertToString
Convert char array to String with separate- Parameters:
src- Raw data.splitNum- Separation interval.split- Separator.- Returns:
- encoded string.
-
convertToCharArray
Delete string Separator and to char array.- Parameters:
src- string.split- separator.- Returns:
- char array.
- Throws:
NullPointerException- when data or separator is null.
-
toFullWidth
Convert half-width string ('\u0021'through'\u007E') to full-width string ('\uFF01'through'\uFF5E')- Parameters:
src- Half-width string.- Returns:
- Full-width string.
-
toHalfWidth
Convert full-width string ('\uFF01'through'\uFF5E') to half-width string ('\u0021'through'\u007E')- 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
-