public final class Strings extends Object
Expression Object for performing String-related operations inside Thymeleaf Standard Expressions.
An object of this class is usually available in variable evaluation expressions with the name #strings.
Modifier and Type | Method and Description |
---|---|
String |
abbreviate(Object target,
int maxSize) |
String |
append(Object target,
String suffix) |
String[] |
arrayAbbreviate(Object[] target,
int maxSize) |
String[] |
arrayAppend(Object[] target,
String suffix) |
String[] |
arrayCapitalize(Object[] target)
Convert the first letter into uppercase (title-case, in fact) for
all the elements in the target array.
|
String[] |
arrayCapitalizeWords(Object[] target)
Convert the first letter of each words of target
to uppercase (title-case, in fact) for
all the elements in the target array.
|
String[] |
arrayCapitalizeWords(Object[] target,
Object delimiters)
Convert the first letter of each words of target
to uppercase (title-case, in fact) for
all the elements in the target array.
|
Boolean[] |
arrayContains(Object[] target,
String fragment) |
Boolean[] |
arrayContainsIgnoreCase(Object[] target,
String fragment) |
String[] |
arrayDefaultString(Object[] target,
Object defaultValue)
Checks if each target element is empty and uses either target element,
or if the target element is empty uses
defaultValue . |
Boolean[] |
arrayEndsWith(Object[] target,
String suffix) |
String[] |
arrayEscapeJava(Object[] target)
Java-escapes all the elements in the target array.
|
String[] |
arrayEscapeJavaScript(Object[] target)
JavaScript-escapes all the elements in the target array.
|
String[] |
arrayEscapeXml(Object[] target)
XML-escapes all the elements in the target array.
|
Integer[] |
arrayIndexOf(Object[] target,
String fragment) |
Boolean[] |
arrayIsEmpty(Object[] target) |
String |
arrayJoin(Object[] stringArray,
String separator) |
Integer[] |
arrayLength(Object[] target) |
String[] |
arrayMultipleReplace(Object[] target,
String[] before,
String[] after) |
String[] |
arrayPrepend(Object[] target,
String prefix) |
String[] |
arrayReplace(Object[] target,
String before,
String after) |
String[] |
arraySplit(Object target,
String separator) |
Boolean[] |
arrayStartsWith(Object[] target,
String prefix) |
String[] |
arraySubstring(Object[] target,
int start)
copy a part of target start beginIndex to the end of target
for all the elements in the target array.
|
String[] |
arraySubstring(Object[] target,
int start,
int end) |
String[] |
arraySubstringAfter(Object[] target,
String substr) |
String[] |
arraySubstringBefore(Object[] target,
String substr) |
String[] |
arrayToLowerCase(Object[] target) |
String[] |
arrayToString(Object[] target)
Performs a null-safe toString() operation on each
element of the array.
|
String[] |
arrayToUpperCase(Object[] target) |
String[] |
arrayTrim(Object[] target) |
String[] |
arrayUnCapitalize(Object[] target)
Convert the first letter into lowercase for
all the elements in the target array.
|
String[] |
arrayUnescapeJava(Object[] target)
Java-unescapes all the elements in the target array.
|
String[] |
arrayUnescapeJavaScript(Object[] target)
JavaScript-unescapes all the elements in the target array.
|
String |
capitalize(Object target)
Convert the first letter of target to uppercase (title-case, in fact).
|
String |
capitalizeWords(Object target)
Convert the first letter of each words of target
to uppercase (title-case, in fact).
|
String |
capitalizeWords(Object target,
Object delimiters)
Convert the first letter of each words of target to uppercase
(title-case, in fact), using the specified delimiter chars for determining
word ends/starts.
|
String |
concat(Object... values) |
String |
concatReplaceNulls(String nullValue,
Object... values) |
Boolean |
contains(Object target,
String fragment) |
Boolean |
containsIgnoreCase(Object target,
String fragment) |
String |
defaultString(Object target,
Object defaultValue)
Checks if target text is empty and uses either target,
or if the target is empty uses
defaultValue . |
Boolean |
endsWith(Object target,
String suffix) |
Boolean |
equals(Object first,
Object second) |
Boolean |
equalsIgnoreCase(Object first,
Object second) |
String |
escapeJava(Object target)
Java-escapes the specified text.
|
String |
escapeJavaScript(Object target)
JavaScript-escapes the specified text.
|
String |
escapeXml(Object target)
XML-escapes the specified text.
|
Integer |
indexOf(Object target,
String fragment) |
Boolean |
isEmpty(Object target) |
Integer |
length(Object target) |
List<String> |
listAbbreviate(List<?> target,
int maxSize) |
List<String> |
listAppend(List<?> target,
String suffix) |
List<String> |
listCapitalize(List<?> target)
Convert the first letter into uppercase (title-case, in fact) for
all the elements in the target list.
|
List<String> |
listCapitalizeWords(List<?> target)
Convert the first letter of each words of target
to uppercase (title-case, in fact) for
all the elements in the target list.
|
List<String> |
listCapitalizeWords(List<?> target,
Object delimiters)
Convert the first letter of each words of target
to uppercase (title-case, in fact) for
all the elements in the target list.
|
List<Boolean> |
listContains(List<?> target,
String fragment) |
List<Boolean> |
listContainsIgnoreCase(List<?> target,
String fragment) |
List<String> |
listDefaultString(List<?> target,
Object defaultValue)
Checks if each target element is empty and uses either target element,
or if the target element is empty uses
defaultValue . |
List<Boolean> |
listEndsWith(List<?> target,
String suffix) |
List<String> |
listEscapeJava(List<?> target)
Java-escapes all the elements in the target list.
|
List<String> |
listEscapeJavaScript(List<?> target)
JavaScript-escapes all the elements in the target list.
|
List<String> |
listEscapeXml(List<?> target)
XML-escapes all the elements in the target list.
|
List<Integer> |
listIndexOf(List<?> target,
String fragment) |
List<Boolean> |
listIsEmpty(List<?> target) |
String |
listJoin(List<?> stringIter,
String separator) |
List<Integer> |
listLength(List<?> target) |
List<String> |
listMultipleReplace(List<?> target,
String[] before,
String[] after) |
List<String> |
listPrepend(List<?> target,
String prefix) |
List<String> |
listReplace(List<?> target,
String before,
String after) |
List<String> |
listSplit(Object target,
String separator) |
List<Boolean> |
listStartsWith(List<?> target,
String prefix) |
List<String> |
listSubstring(List<?> target,
int start)
copy a part of target start beginIndex to the end of target
for all the elements in the target list.
|
List<String> |
listSubstring(List<?> target,
int start,
int end) |
List<String> |
listSubstringAfter(List<?> target,
String substr) |
List<String> |
listSubstringBefore(List<?> target,
String substr) |
List<String> |
listToLowerCase(List<?> target) |
List<String> |
listToString(List<?> target)
Performs a null-safe toString() operation on each
element of the list.
|
List<String> |
listToUpperCase(List<?> target) |
List<String> |
listTrim(List<?> target) |
List<String> |
listUnCapitalize(List<?> target)
Convert the first letter into lowercase for
all the elements in the target list.
|
List<String> |
listUnescapeJava(List<?> target)
Java-unescapes all the elements in the target list.
|
List<String> |
listUnescapeJavaScript(List<?> target)
JavaScript-unescapes all the elements in the target list.
|
String |
multipleReplace(Object target,
String[] before,
String[] after) |
String |
prepend(Object target,
String prefix) |
String |
randomAlphanumeric(int count)
Builds a random String using characters 0..9 and A..Z.
|
String |
repeat(Object target,
int times) |
String |
replace(Object target,
String before,
String after) |
Set<String> |
setAbbreviate(Set<?> target,
int maxSize) |
Set<String> |
setAppend(Set<?> target,
String suffix) |
Set<String> |
setCapitalize(Set<?> target)
Convert the first letter into uppercase (title-case, in fact) for
all the elements in the target set.
|
Set<String> |
setCapitalizeWords(Set<?> target)
Convert the first letter of each words of target
to uppercase (title-case, in fact)
for all the elements in the target set.
|
Set<String> |
setCapitalizeWords(Set<?> target,
Object delimiters)
Convert the first letter of each words of target
to uppercase (title-case, in fact) for
all the elements in the target set.
|
Set<Boolean> |
setContains(Set<?> target,
String fragment) |
Set<Boolean> |
setContainsIgnoreCase(Set<?> target,
String fragment) |
Set<String> |
setDefaultString(Set<?> target,
Object defaultValue)
Checks if each target element is empty and uses either target element,
or if the target element is empty uses
defaultValue . |
Set<Boolean> |
setEndsWith(Set<?> target,
String suffix) |
Set<String> |
setEscapeJava(Set<?> target)
Java-escapes all the elements in the target set.
|
Set<String> |
setEscapeJavaScript(Set<?> target)
JavaScript-escapes all the elements in the target set.
|
Set<String> |
setEscapeXml(Set<?> target)
XML-escapes all the elements in the target set.
|
Set<Integer> |
setIndexOf(Set<?> target,
String fragment) |
Set<Boolean> |
setIsEmpty(Set<?> target) |
String |
setJoin(Set<?> stringIter,
String separator) |
Set<Integer> |
setLength(Set<?> target) |
Set<String> |
setMultipleReplace(Set<?> target,
String[] before,
String[] after) |
Set<String> |
setPrepend(Set<?> target,
String prefix) |
Set<String> |
setReplace(Set<?> target,
String before,
String after) |
Set<String> |
setSplit(Object target,
String separator) |
Set<Boolean> |
setStartsWith(Set<?> target,
String prefix) |
Set<String> |
setSubstring(Set<?> target,
int start)
copy a part of target start beginIndex to the end of target
for all the elements in the target set.
|
Set<String> |
setSubstring(Set<?> target,
int start,
int end) |
Set<String> |
setSubstringAfter(Set<?> target,
String substr) |
Set<String> |
setSubstringBefore(Set<?> target,
String substr) |
Set<String> |
setToLowerCase(Set<?> target) |
Set<String> |
setToString(Set<?> target)
Performs a null-safe toString() operation on each
element of the set.
|
Set<String> |
setToUpperCase(Set<?> target) |
Set<String> |
setTrim(Set<?> target) |
Set<String> |
setUnCapitalize(Set<?> target)
Convert the first letter into lowercase for
all the elements in the target set.
|
Set<String> |
setUnescapeJava(Set<?> target)
Java-unescapes all the elements in the target set.
|
Set<String> |
setUnescapeJavaScript(Set<?> target)
JavaScript-unescapes all the elements in the target set.
|
Boolean |
startsWith(Object target,
String prefix) |
String |
substring(Object target,
int start)
copy a part of target start beginIndex to the end of target.
|
String |
substring(Object target,
int start,
int end) |
String |
substringAfter(Object target,
String substr) |
String |
substringBefore(Object target,
String substr) |
String |
toLowerCase(Object target) |
String |
toString(Object target)
Performs a null-safe toString() operation.
|
String |
toUpperCase(Object target) |
String |
trim(Object target) |
String |
unCapitalize(Object target)
Convert the first letter of target to lowercase.
|
String |
unescapeJava(Object target)
Java-unescapes the specified text.
|
String |
unescapeJavaScript(Object target)
JavaScript-unescapes the specified text.
|
public Strings(Locale locale)
public String toString(Object target)
Performs a null-safe toString() operation.
target
- the object on which toString will be executedpublic String[] arrayToString(Object[] target)
Performs a null-safe toString() operation on each element of the array.
target
- the array of objects on which toString will be executedpublic List<String> listToString(List<?> target)
Performs a null-safe toString() operation on each element of the list.
target
- the list of objects on which toString will be executedpublic Set<String> setToString(Set<?> target)
Performs a null-safe toString() operation on each element of the set.
target
- the set of objects on which toString will be executedpublic Boolean equals(Object first, Object second)
first
- firstsecond
- secondpublic Boolean equalsIgnoreCase(Object first, Object second)
first
- firstsecond
- secondpublic String substring(Object target, int start)
copy a part of target start beginIndex to the end of target. If non-String object, toString() will be called.
target
- source of the copy.start
- index where the copy start.public String[] arraySubstring(Object[] target, int start)
copy a part of target start beginIndex to the end of target for all the elements in the target array. If non-String object, toString() will be called.
target
- source of the copy.start
- index where the copy start.public List<String> listSubstring(List<?> target, int start)
copy a part of target start beginIndex to the end of target for all the elements in the target list. If non-String object, toString() will be called.
target
- source of the copy.start
- index where the copy start.public Set<String> setSubstring(Set<?> target, int start)
copy a part of target start beginIndex to the end of target for all the elements in the target set. If non-String object, toString() will be called.
target
- source of the copy.start
- index where the copy start.public String repeat(Object target, int times)
target
- targettimes
- timespublic String concat(Object... values)
values
- valuespublic String concatReplaceNulls(String nullValue, Object... values)
nullValue
- nullValuevalues
- valuespublic String[] arrayMultipleReplace(Object[] target, String[] before, String[] after)
public List<String> listMultipleReplace(List<?> target, String[] before, String[] after)
public Set<String> setMultipleReplace(Set<?> target, String[] before, String[] after)
public String capitalize(Object target)
Convert the first letter of target to uppercase (title-case, in fact).
target
- the String to be capitalized.
If non-String object, toString() will be called.public String[] arrayCapitalize(Object[] target)
Convert the first letter into uppercase (title-case, in fact) for all the elements in the target array.
target
- the array of Strings to be capitalized.
If non-String objects, toString() will be called.public List<String> listCapitalize(List<?> target)
Convert the first letter into uppercase (title-case, in fact) for all the elements in the target list.
target
- the list of Strings to be capitalized.
If non-String objects, toString() will be called.public Set<String> setCapitalize(Set<?> target)
Convert the first letter into uppercase (title-case, in fact) for all the elements in the target set.
target
- the set of Strings to be capitalized.
If non-String objects, toString() will be called.public String unCapitalize(Object target)
Convert the first letter of target to lowercase.
target
- the String to be uncapitalized.
If non-String object, toString() will be called.public String[] arrayUnCapitalize(Object[] target)
Convert the first letter into lowercase for all the elements in the target array.
target
- the array of Strings to be uncapitalized.
If non-String objects, toString() will be called.public List<String> listUnCapitalize(List<?> target)
Convert the first letter into lowercase for all the elements in the target list.
target
- the list of Strings to be uncapitalized.
If non-String objects, toString() will be called.public Set<String> setUnCapitalize(Set<?> target)
Convert the first letter into lowercase for all the elements in the target set.
target
- the set of Strings to be uncapitalized.
If non-String objects, toString() will be called.public String capitalizeWords(Object target)
Convert the first letter of each 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 documentation).
target
- the String to be capitalized.
If non-String object, toString() will be called.public String[] arrayCapitalizeWords(Object[] target)
Convert the first letter of each words of target to uppercase (title-case, in fact) for all the elements in the target array. The default delimiter characters between the words are the whitespace characters (see Characters.IsWhiteSpace method in the Java documentation).
target
- the array of Strings to be capitalized.
If non-String objects, toString() will be called.public List<String> listCapitalizeWords(List<?> target)
Convert the first letter of each words of target to uppercase (title-case, in fact) for all the elements in the target list. The default delimiter characters between the words are the whitespace characters (see Characters.IsWhiteSpace method in the Java documentation).
target
- the list of Strings to be capitalized.
If non-String objects, toString() will be called.public Set<String> setCapitalizeWords(Set<?> target)
Convert the first letter of each words of target to uppercase (title-case, in fact) for all the elements in the target set. The default delimiter characters between the words are the whitespace characters (see Characters.IsWhiteSpace method in the Java documentation).
target
- the set of Strings to be capitalized.
If non-String objects, toString() will be called.public String capitalizeWords(Object target, Object delimiters)
Convert the first letter of each words of target to uppercase (title-case, in fact), using the specified delimiter chars for determining word ends/starts.
target
- the String to be capitalized.
If non-String object, toString() will be called.delimiters
- the delimiters of the words.
If non-String object, toString() will be called.public String[] arrayCapitalizeWords(Object[] target, Object delimiters)
Convert the first letter of each words of target to uppercase (title-case, in fact) for all the elements in the target array. The specified delimiter chars will be used for determining word ends/starts.
target
- the array of Strings to be capitalized.
If non-String objects, toString() will be called.delimiters
- the delimiters of the words.
If non-String object, toString() will be called.public List<String> listCapitalizeWords(List<?> target, Object delimiters)
Convert the first letter of each words of target to uppercase (title-case, in fact) for all the elements in the target list. The specified delimiter chars will be used for determining word ends/starts.
target
- the list of Strings to be capitalized.
If non-String objects, toString() will be called.delimiters
- the delimiters of the words.
If non-String object, toString() will be called.public Set<String> setCapitalizeWords(Set<?> target, Object delimiters)
Convert the first letter of each words of target to uppercase (title-case, in fact) for all the elements in the target set. The specified delimiter chars will be used for determining word ends/starts.
target
- the set of Strings to be capitalized.
If non-String objects, toString() will be called.delimiters
- the delimiters of the words.
If non-String object, toString()public String escapeXml(Object target)
XML-escapes the specified text.
target
- the text to be escapedpublic String[] arrayEscapeXml(Object[] target)
XML-escapes all the elements in the target array.
target
- the array of Strings to be escaped.
If non-String objects, toString() will be called.public List<String> listEscapeXml(List<?> target)
XML-escapes all the elements in the target list.
target
- the list of Strings to be escaped.
If non-String objects, toString() will be called.public Set<String> setEscapeXml(Set<?> target)
XML-escapes all the elements in the target set.
target
- the list of Strings to be escaped.
If non-String objects, toString() will be called.public String escapeJavaScript(Object target)
JavaScript-escapes the specified text.
target
- the text to be escapedpublic String[] arrayEscapeJavaScript(Object[] target)
JavaScript-escapes all the elements in the target array.
target
- the array of Strings to be escaped.
If non-String objects, toString() will be called.public List<String> listEscapeJavaScript(List<?> target)
JavaScript-escapes all the elements in the target list.
target
- the list of Strings to be escaped.
If non-String objects, toString() will be called.public Set<String> setEscapeJavaScript(Set<?> target)
JavaScript-escapes all the elements in the target set.
target
- the list of Strings to be escaped.
If non-String objects, toString() will be called.public String unescapeJavaScript(Object target)
JavaScript-unescapes the specified text.
target
- the text to be unescapedpublic String[] arrayUnescapeJavaScript(Object[] target)
JavaScript-unescapes all the elements in the target array.
target
- the array of Strings to be unescaped.
If non-String objects, toString() will be called.public List<String> listUnescapeJavaScript(List<?> target)
JavaScript-unescapes all the elements in the target list.
target
- the list of Strings to be unescaped.
If non-String objects, toString() will be called.public Set<String> setUnescapeJavaScript(Set<?> target)
JavaScript-unescapes all the elements in the target set.
target
- the list of Strings to be unescaped.
If non-String objects, toString() will be called.public String escapeJava(Object target)
Java-escapes the specified text.
target
- the text to be escapedpublic String[] arrayEscapeJava(Object[] target)
Java-escapes all the elements in the target array.
target
- the array of Strings to be escaped.
If non-String objects, toString() will be called.public List<String> listEscapeJava(List<?> target)
Java-escapes all the elements in the target list.
target
- the list of Strings to be escaped.
If non-String objects, toString() will be called.public Set<String> setEscapeJava(Set<?> target)
Java-escapes all the elements in the target set.
target
- the list of Strings to be escaped.
If non-String objects, toString() will be called.public String unescapeJava(Object target)
Java-unescapes the specified text.
target
- the text to be unescapedpublic String[] arrayUnescapeJava(Object[] target)
Java-unescapes all the elements in the target array.
target
- the array of Strings to be unescaped.
If non-String objects, toString() will be called.public List<String> listUnescapeJava(List<?> target)
Java-unescapes all the elements in the target list.
target
- the list of Strings to be unescaped.
If non-String objects, toString() will be called.public Set<String> setUnescapeJava(Set<?> target)
Java-unescapes all the elements in the target set.
target
- the list of Strings to be unescaped.
If non-String objects, toString() will be called.public String randomAlphanumeric(int count)
Builds a random String using characters 0..9 and A..Z.
count
- length of the generated Stringpublic String defaultString(Object target, Object defaultValue)
Checks if target text is empty and uses either target,
or if the target is empty uses defaultValue
.
target
- value that to be checked if is null or empty
If non-String objects, toString() will be called.defaultValue
- value to use if target is empty
If non-String objects, toString() will be called.defaultValue
public String[] arrayDefaultString(Object[] target, Object defaultValue)
Checks if each target element is empty and uses either target element,
or if the target element is empty uses defaultValue
.
target
- the array of values that to be checked if is null or empty
If non-String objects, toString() will be called.defaultValue
- value to return if target is empty
If non-String objects, toString() will be called.defaultString(Object, Object)
for each element of the target.public List<String> listDefaultString(List<?> target, Object defaultValue)
Checks if each target element is empty and uses either target element,
or if the target element is empty uses defaultValue
.
target
- the list of values that to be checked if is null or empty
If non-String objects, toString() will be called.defaultValue
- value to return if target is empty
If non-String objects, toString() will be called.List<String>
with the result of
defaultString(Object, Object)
for each element of the target.public Set<String> setDefaultString(Set<?> target, Object defaultValue)
Checks if each target element is empty and uses either target element,
or if the target element is empty uses defaultValue
.
target
- the set of values that to be checked if is null or empty
If non-String objects, toString() will be called.defaultValue
- value to return if target is empty
If non-String objects, toString() will be called.Set<String>
with the result of
defaultString(Object, Object)
for each element of the target.Copyright © 2016 The THYMELEAF team. All rights reserved.