Class StringUtils
Utility methods for String objects.
This class is used as a basis for the methods offered by
Strings, which in turn are the
methods offered by the #strings utility object in variable
expressions.
- Since:
- 1.0
- Author:
- Daniel Fernández, Le Roux Bernard, Soraya Sánchez Labandeira
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stringabbreviate(Object target, int maxSize) static Stringstatic Stringcapitalize(Object target) Convert the first letter of target to uppercase (title-case, in fact).static StringcapitalizeWords(Object target) Convert all the first letter of the words of target to uppercase (title-case, in fact).static StringcapitalizeWords(Object target, Object delimiters) Convert all the first letter of the words of target to uppercase (title-case, in fact), using the specified delimiter chars for determining word ends/starts.static Stringstatic StringconcatReplaceNulls(String nullValue, Object... values) static Booleanstatic BooleancontainsIgnoreCase(Object target, String fragment, Locale locale) static Booleanstatic Booleanstatic BooleanequalsIgnoreCase(Object first, Object second) static StringescapeJava(Object target) Escapes the specified target text as required for Java code.static StringescapeJavaScript(Object target) Escapes the specified target text as required for JavaScript code.static StringXML-escapes the specified text.static Integerstatic booleanstatic booleanisEmptyOrWhitespace(String target) static Stringstatic Stringstatic Stringstatic Integerstatic StringRemoves all whitespaces and control chars at all positions, and transforms to lower case.static Stringstatic StringrandomAlphanumeric(int count) static Stringstatic Stringstatic String[]static BooleanstartsWith(Object target, String prefix) static Stringcopy a part of target start beginIndex to the end of target.static Stringstatic StringsubstringAfter(Object target, String substr) static StringsubstringBefore(Object target, String substr) static StringtoLowerCase(Object target, Locale locale) static StringPerforms a null-safetoString()operation.static StringtoUpperCase(Object target, Locale locale) static Stringstatic StringunCapitalize(Object target) Convert the first letter of target to lowercase.static StringunescapeJava(Object target) Un-escapes the specified Java-escaped target text back to normal form.static StringunescapeJavaScript(Object target) Un-escapes the specified JavaScript-escaped target text back to normal form.
-
Method Details
-
toString
Performs a null-safe
toString()operation.- Parameters:
target- the object on which toString will be executed- Returns:
- the result of calling
target.toString()if target is not null,nullif target is null. - Since:
- 2.0.12
-
abbreviate
-
equals
- Parameters:
first- firstsecond- second- Returns:
- the result
- Since:
- 2.0.16
-
equalsIgnoreCase
- Parameters:
first- firstsecond- second- Returns:
- the result
- Since:
- 2.0.16
-
contains
-
containsIgnoreCase
-
startsWith
-
endsWith
-
substring
-
substring
copy a part of target start beginIndex to the end of target. If non-String object, toString() will be called.
- Parameters:
target- source of the copy.beginIndex- index where the copy start.- Returns:
- part of target, or
nullif target is null. - Since:
- 1.1.2
-
substringAfter
-
substringBefore
-
prepend
-
append
-
repeat
- Parameters:
target- targettimes- times- Returns:
- the result
- Since:
- 2.1.0
-
concat
- Parameters:
values- values- Returns:
- the result
- Since:
- 2.0.16
-
concatReplaceNulls
- Parameters:
nullValue- nullValuevalues- values- Returns:
- the result
- Since:
- 2.0.16
-
indexOf
-
isEmpty
- Parameters:
target- target- Returns:
- the result
- Since:
- 2.1.0
-
isEmptyOrWhitespace
-
join
-
join
-
join
-
split
-
length
-
replace
-
toUpperCase
-
toLowerCase
-
trim
-
pack
Removes all whitespaces and control chars at all positions, and transforms to lower case.- Parameters:
target- the string to be packed- Returns:
- the packed string
- Since:
- 3.0.12
-
capitalize
Convert the first letter of target to uppercase (title-case, in fact).
- Parameters:
target- the String to be capitalized. If non-String object, toString() will be called.- Returns:
- String the result of capitalizing the target.
- Since:
- 1.1.2
-
unCapitalize
Convert the first letter of target to lowercase.
- Parameters:
target- the String to be uncapitalized. If non-String object, toString() will be called.- Returns:
- String the result of uncapitalizing the target.
- Since:
- 1.1.2
-
capitalizeWords
Convert all the first letter of the words of target to uppercase (title-case, in fact). The default delimiter characters between the words are the whitespace characters (see Characters.IsWhiteSpace method in the Java doc).
- Parameters:
target- the String to be capitalized. If non-String object, toString() will be called.- Returns:
- String the result of capitalizing the target.
- Since:
- 1.1.2
-
capitalizeWords
Convert all the first letter of the words of target to uppercase (title-case, in fact), using the specified delimiter chars for determining word ends/starts.
- Parameters:
target- the String to be capitalized. If non-String object, toString() will be called.delimiters- delimiters of the words. If non-String object, toString() will be called.- Returns:
- String the result of capitalizing the target.
- Since:
- 1.1.2
-
escapeXml
XML-escapes the specified text.
- Parameters:
target- the text to be escaped- Returns:
- the escaped text.
- Since:
- 2.0.9
-
escapeJavaScript
Escapes the specified target text as required for JavaScript code.
- Parameters:
target- the text to be escaped- Returns:
- the escaped text.
- Since:
- 2.0.11
-
escapeJava
Escapes the specified target text as required for Java code.
- Parameters:
target- the text to be escaped- Returns:
- the escaped text.
- Since:
- 2.0.11
-
unescapeJavaScript
Un-escapes the specified JavaScript-escaped target text back to normal form.
- Parameters:
target- the text to be unescaped- Returns:
- the unescaped text.
- Since:
- 2.0.11
-
unescapeJava
Un-escapes the specified Java-escaped target text back to normal form.
- Parameters:
target- the text to be unescaped- Returns:
- the unescaped text.
- Since:
- 2.0.11
-
randomAlphanumeric
-