Class Strings
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
.
- Since:
- 1.0
- Author:
- Daniel Fernández, Bernard Le Roux
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabbreviate
(Object target, int maxSize) 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 usesdefaultValue
.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) 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-safetoString()
operation on each element of the array.String[]
arrayToUpperCase
(Object[] target) String[]
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.capitalize
(Object target) Convert the first letter of target to uppercase (title-case, in fact).capitalizeWords
(Object target) Convert the first letter of each words of target to uppercase (title-case, in fact).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.concatReplaceNulls
(String nullValue, Object... values) containsIgnoreCase
(Object target, String fragment) defaultString
(Object target, Object defaultValue) Checks if target text is empty and uses either target, or if the target is empty usesdefaultValue
.equalsIgnoreCase
(Object first, Object second) escapeJava
(Object target) Java-escapes the specified text.escapeJavaScript
(Object target) JavaScript-escapes the specified text.XML-escapes the specified text.listAbbreviate
(List<?> target, int maxSize) listAppend
(List<?> target, String suffix) listCapitalize
(List<?> target) Convert the first letter into uppercase (title-case, in fact) for all the elements in the target list.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.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.listContains
(List<?> target, String fragment) listContainsIgnoreCase
(List<?> target, String fragment) listDefaultString
(List<?> target, Object defaultValue) Checks if each target element is empty and uses either target element, or if the target element is empty usesdefaultValue
.listEndsWith
(List<?> target, String suffix) listEscapeJava
(List<?> target) Java-escapes all the elements in the target list.listEscapeJavaScript
(List<?> target) JavaScript-escapes all the elements in the target list.listEscapeXml
(List<?> target) XML-escapes all the elements in the target list.listIndexOf
(List<?> target, String fragment) listIsEmpty
(List<?> target) listLength
(List<?> target) listMultipleReplace
(List<?> target, String[] before, String[] after) listPrepend
(List<?> target, String prefix) listReplace
(List<?> target, String before, String after) listStartsWith
(List<?> target, String prefix) 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.listSubstring
(List<?> target, int start, int end) listSubstringAfter
(List<?> target, String substr) listSubstringBefore
(List<?> target, String substr) listToLowerCase
(List<?> target) listToString
(List<?> target) Performs a null-safetoString()
operation on each element of the list.listToUpperCase
(List<?> target) listUnCapitalize
(List<?> target) Convert the first letter into lowercase for all the elements in the target list.listUnescapeJava
(List<?> target) Java-unescapes all the elements in the target list.listUnescapeJavaScript
(List<?> target) JavaScript-unescapes all the elements in the target list.multipleReplace
(Object target, String[] before, String[] after) randomAlphanumeric
(int count) Builds a random String using characters 0..9 and A..Z.setAbbreviate
(Set<?> target, int maxSize) setCapitalize
(Set<?> target) Convert the first letter into uppercase (title-case, in fact) for all the elements in the target set.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.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.setContains
(Set<?> target, String fragment) setContainsIgnoreCase
(Set<?> target, String fragment) setDefaultString
(Set<?> target, Object defaultValue) Checks if each target element is empty and uses either target element, or if the target element is empty usesdefaultValue
.setEndsWith
(Set<?> target, String suffix) setEscapeJava
(Set<?> target) Java-escapes all the elements in the target set.setEscapeJavaScript
(Set<?> target) JavaScript-escapes all the elements in the target set.setEscapeXml
(Set<?> target) XML-escapes all the elements in the target set.setIndexOf
(Set<?> target, String fragment) setIsEmpty
(Set<?> target) setMultipleReplace
(Set<?> target, String[] before, String[] after) setPrepend
(Set<?> target, String prefix) setReplace
(Set<?> target, String before, String after) setStartsWith
(Set<?> target, String prefix) 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.setSubstring
(Set<?> target, int start, int end) setSubstringAfter
(Set<?> target, String substr) setSubstringBefore
(Set<?> target, String substr) setToLowerCase
(Set<?> target) setToString
(Set<?> target) Performs a null-safetoString()
operation on each element of the set.setToUpperCase
(Set<?> target) setUnCapitalize
(Set<?> target) Convert the first letter into lowercase for all the elements in the target set.setUnescapeJava
(Set<?> target) Java-unescapes all the elements in the target set.setUnescapeJavaScript
(Set<?> target) JavaScript-unescapes all the elements in the target set.startsWith
(Object target, String prefix) copy a part of target start beginIndex to the end of target.substringAfter
(Object target, String substr) substringBefore
(Object target, String substr) toLowerCase
(Object target) Performs a null-safetoString()
operation.toUpperCase
(Object target) unCapitalize
(Object target) Convert the first letter of target to lowercase.unescapeJava
(Object target) Java-unescapes the specified text.unescapeJavaScript
(Object target) JavaScript-unescapes the specified text.
-
Constructor Details
-
Strings
-
-
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,null
if target is null. - Since:
- 2.0.12
-
arrayToString
Performs a null-safe
toString()
operation on each element of the array.- Parameters:
target
- the array of objects on which toString will be executed- Returns:
- for each element: the result of calling
target.toString()
if target is not null,null
if target is null. - Since:
- 2.0.12
-
listToString
Performs a null-safe
toString()
operation on each element of the list.- Parameters:
target
- the list of objects on which toString will be executed- Returns:
- for each element: the result of calling
target.toString()
if target is not null,null
if target is null. - Since:
- 2.0.12
-
setToString
Performs a null-safe
toString()
operation on each element of the set.- Parameters:
target
- the set of objects on which toString will be executed- Returns:
- for each element: the result of calling
target.toString()
if target is not null,null
if target is null. - Since:
- 2.0.12
-
abbreviate
-
arrayAbbreviate
-
listAbbreviate
-
setAbbreviate
-
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
-
arrayContains
-
listContains
-
setContains
-
containsIgnoreCase
-
arrayContainsIgnoreCase
-
listContainsIgnoreCase
-
setContainsIgnoreCase
-
startsWith
-
arrayStartsWith
-
listStartsWith
-
setStartsWith
-
endsWith
-
arrayEndsWith
-
listEndsWith
-
setEndsWith
-
substring
-
arraySubstring
-
listSubstring
-
setSubstring
-
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.start
- index where the copy start.- Returns:
- part of target, or
null
if target is null. - Since:
- 1.1.2
-
arraySubstring
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.
- Parameters:
target
- source of the copy.start
- index where the copy start.- Returns:
- part of target, or
null
if target is null. - Since:
- 1.1.2
-
listSubstring
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.
- Parameters:
target
- source of the copy.start
- index where the copy start.- Returns:
- part of target, or
null
if target is null. - Since:
- 1.1.2
-
setSubstring
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.
- Parameters:
target
- source of the copy.start
- index where the copy start.- Returns:
- part of target, or
null
if target is null. - Since:
- 1.1.2
-
substringAfter
-
arraySubstringAfter
-
listSubstringAfter
-
setSubstringAfter
-
substringBefore
-
arraySubstringBefore
-
listSubstringBefore
-
setSubstringBefore
-
prepend
-
arrayPrepend
-
listPrepend
-
setPrepend
-
repeat
- Parameters:
target
- targettimes
- times- Returns:
- the result
- Since:
- 2.1.0
-
append
-
concat
- Parameters:
values
- values- Returns:
- the result
- Since:
- 2.0.16
-
concatReplaceNulls
- Parameters:
nullValue
- nullValuevalues
- values- Returns:
- the result
- Since:
- 2.0.16
-
arrayAppend
-
listAppend
-
setAppend
-
indexOf
-
arrayIndexOf
-
listIndexOf
-
setIndexOf
-
isEmpty
-
arrayIsEmpty
-
listIsEmpty
-
setIsEmpty
-
arrayJoin
-
listJoin
-
setJoin
-
arraySplit
-
listSplit
-
setSplit
-
length
-
arrayLength
-
listLength
-
setLength
-
replace
-
arrayReplace
-
listReplace
-
setReplace
-
multipleReplace
-
arrayMultipleReplace
-
listMultipleReplace
-
setMultipleReplace
-
toUpperCase
-
arrayToUpperCase
-
listToUpperCase
-
setToUpperCase
-
toLowerCase
-
arrayToLowerCase
-
listToLowerCase
-
setToLowerCase
-
trim
-
arrayTrim
-
listTrim
-
setTrim
-
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
-
arrayCapitalize
Convert the first letter into uppercase (title-case, in fact) for all the elements in the target array.
- Parameters:
target
- the array of Strings to be capitalized. If non-String objects, toString() will be called.- Returns:
- a String[] with the result of capitalizing each element of the target.
- Since:
- 1.1.2
-
listCapitalize
Convert the first letter into uppercase (title-case, in fact) for all the elements in the target list.
- Parameters:
target
- the list of Strings to be capitalized. If non-String objects, toString() will be called.- Returns:
- a List with the result of capitalizing each element of the target.
- Since:
- 1.1.2
-
setCapitalize
Convert the first letter into uppercase (title-case, in fact) for all the elements in the target set.
- Parameters:
target
- the set of Strings to be capitalized. If non-String objects, toString() will be called.- Returns:
- a Set with the result of capitalizing each element of 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
-
arrayUnCapitalize
Convert the first letter into lowercase for all the elements in the target array.
- Parameters:
target
- the array of Strings to be uncapitalized. If non-String objects, toString() will be called.- Returns:
- a String[] with the result of uncapitalizing each element of the target.
- Since:
- 1.1.2
-
listUnCapitalize
Convert the first letter into lowercase for all the elements in the target list.
- Parameters:
target
- the list of Strings to be uncapitalized. If non-String objects, toString() will be called.- Returns:
- a List with the result of uncapitalizing each element of the target.
- Since:
- 1.1.2
-
setUnCapitalize
Convert the first letter into lowercase for all the elements in the target set.
- Parameters:
target
- the set of Strings to be uncapitalized. If non-String objects, toString() will be called.- Returns:
- a Set with the result of uncapitalizing each element of the target.
- Since:
- 1.1.2
-
capitalizeWords
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).
- 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
-
arrayCapitalizeWords
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).
- Parameters:
target
- the array of Strings to be capitalized. If non-String objects, toString() will be called.- Returns:
- a String[] with the result of capitalizing each element of the target.
- Since:
- 1.1.2
-
listCapitalizeWords
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).
- Parameters:
target
- the list of Strings to be capitalized. If non-String objects, toString() will be called.- Returns:
- a List with the result of capitalizing each element of the target.
- Since:
- 1.1.2
-
setCapitalizeWords
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).
- Parameters:
target
- the set of Strings to be capitalized. If non-String objects, toString() will be called.- Returns:
- a Set with the result of capitalizing each element of the target.
- Since:
- 1.1.2
-
capitalizeWords
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.
- Parameters:
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.- Returns:
- String the result of capitalizing the target.
- Since:
- 1.1.2
-
arrayCapitalizeWords
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.
- Parameters:
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.- Returns:
- a String[] with the result of capitalizing each element of the target.
- Since:
- 1.1.2
-
listCapitalizeWords
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.
- Parameters:
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.- Returns:
- a List with the result of capitalizing each element of the target.
- Since:
- 1.1.2
-
setCapitalizeWords
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.
- Parameters:
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()- Returns:
- a Set with the result of capitalizing each element of 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
-
arrayEscapeXml
XML-escapes all the elements in the target array.
- Parameters:
target
- the array of Strings to be escaped. If non-String objects, toString() will be called.- Returns:
- a String[] with the result of each each element of the target.
- Since:
- 2.0.9
-
listEscapeXml
XML-escapes all the elements in the target list.
- Parameters:
target
- the list of Strings to be escaped. If non-String objects, toString() will be called.- Returns:
- a List with the result of each each element of the target.
- Since:
- 2.0.9
-
setEscapeXml
XML-escapes all the elements in the target set.
- Parameters:
target
- the list of Strings to be escaped. If non-String objects, toString() will be called.- Returns:
- a Set with the result of each each element of the target.
- Since:
- 2.0.9
-
escapeJavaScript
JavaScript-escapes the specified text.
- Parameters:
target
- the text to be escaped- Returns:
- the escaped text.
- Since:
- 2.0.11
-
arrayEscapeJavaScript
JavaScript-escapes all the elements in the target array.
- Parameters:
target
- the array of Strings to be escaped. If non-String objects, toString() will be called.- Returns:
- a String[] with the result of each each element of the target.
- Since:
- 2.0.11
-
listEscapeJavaScript
JavaScript-escapes all the elements in the target list.
- Parameters:
target
- the list of Strings to be escaped. If non-String objects, toString() will be called.- Returns:
- a List with the result of each each element of the target.
- Since:
- 2.0.11
-
setEscapeJavaScript
JavaScript-escapes all the elements in the target set.
- Parameters:
target
- the list of Strings to be escaped. If non-String objects, toString() will be called.- Returns:
- a Set with the result of each each element of the target.
- Since:
- 2.0.11
-
unescapeJavaScript
JavaScript-unescapes the specified text.
- Parameters:
target
- the text to be unescaped- Returns:
- the unescaped text.
- Since:
- 2.0.11
-
arrayUnescapeJavaScript
JavaScript-unescapes all the elements in the target array.
- Parameters:
target
- the array of Strings to be unescaped. If non-String objects, toString() will be called.- Returns:
- a String[] with the result of each each element of the target.
- Since:
- 2.0.11
-
listUnescapeJavaScript
JavaScript-unescapes all the elements in the target list.
- Parameters:
target
- the list of Strings to be unescaped. If non-String objects, toString() will be called.- Returns:
- a List with the result of each each element of the target.
- Since:
- 2.0.11
-
setUnescapeJavaScript
JavaScript-unescapes all the elements in the target set.
- Parameters:
target
- the list of Strings to be unescaped. If non-String objects, toString() will be called.- Returns:
- a Set with the result of each each element of the target.
- Since:
- 2.0.11
-
escapeJava
Java-escapes the specified text.
- Parameters:
target
- the text to be escaped- Returns:
- the escaped text.
- Since:
- 2.0.11
-
arrayEscapeJava
Java-escapes all the elements in the target array.
- Parameters:
target
- the array of Strings to be escaped. If non-String objects, toString() will be called.- Returns:
- a String[] with the result of each each element of the target.
- Since:
- 2.0.11
-
listEscapeJava
Java-escapes all the elements in the target list.
- Parameters:
target
- the list of Strings to be escaped. If non-String objects, toString() will be called.- Returns:
- a List with the result of each each element of the target.
- Since:
- 2.0.11
-
setEscapeJava
Java-escapes all the elements in the target set.
- Parameters:
target
- the list of Strings to be escaped. If non-String objects, toString() will be called.- Returns:
- a Set with the result of each each element of the target.
- Since:
- 2.0.11
-
unescapeJava
Java-unescapes the specified text.
- Parameters:
target
- the text to be unescaped- Returns:
- the unescaped text.
- Since:
- 2.0.11
-
arrayUnescapeJava
Java-unescapes all the elements in the target array.
- Parameters:
target
- the array of Strings to be unescaped. If non-String objects, toString() will be called.- Returns:
- a String[] with the result of each each element of the target.
- Since:
- 2.0.11
-
listUnescapeJava
Java-unescapes all the elements in the target list.
- Parameters:
target
- the list of Strings to be unescaped. If non-String objects, toString() will be called.- Returns:
- a List with the result of each each element of the target.
- Since:
- 2.0.11
-
setUnescapeJava
Java-unescapes all the elements in the target set.
- Parameters:
target
- the list of Strings to be unescaped. If non-String objects, toString() will be called.- Returns:
- a Set with the result of each each element of the target.
- Since:
- 2.0.11
-
randomAlphanumeric
Builds a random String using characters 0..9 and A..Z.
- Parameters:
count
- length of the generated String- Returns:
- a random String
- Since:
- 2.1.0
-
defaultString
Checks if target text is empty and uses either target, or if the target is empty uses
defaultValue
.- Parameters:
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.- Returns:
- either target, or if the target is empty
defaultValue
- Since:
- 2.1.3
-
arrayDefaultString
Checks if each target element is empty and uses either target element, or if the target element is empty uses
defaultValue
.- Parameters:
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.- Returns:
- a String[] with the result of
defaultString(Object, Object)
for each element of the target. - Since:
- 2.1.3
-
listDefaultString
Checks if each target element is empty and uses either target element, or if the target element is empty uses
defaultValue
.- Parameters:
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.- Returns:
- a
List<String>
with the result ofdefaultString(Object, Object)
for each element of the target. - Since:
- 2.1.3
-
setDefaultString
Checks if each target element is empty and uses either target element, or if the target element is empty uses
defaultValue
.- Parameters:
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.- Returns:
- a
Set<String>
with the result ofdefaultString(Object, Object)
for each element of the target. - Since:
- 2.1.3
-