Testing Formatted Strings
The following functions are available for testing formatted string fields:
Function | Description |
---|---|
trim(String s) |
Returns a copy of s, with leading and trailing white space omitted. |
truncate(String s, int n) |
Returns the first n-3 characters of the s with "…" appended. The total length of the returned string is n. |
concat(String s1, String s2) |
Returns a string that concatenates s2 to the end of s1. |
substring(String s, int beginIndex, int endIndex) |
Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex- 1. Thus the length of the substring is endIndex - beginIndex. |
toUpperCase(String s) |
Converts all of the characters of s to upper case. |
toLowerCase(String s) |
Converts all of the characters of s to lower case. |
toTitleCase(String s) |
Converts all of the characters of s to title case. |
toPlural(String s) |
Converts s to be plural by adding the character ‘s’ unless s ends in ‘s’ in which case ‘es’ is added. |
escapeQuotes(String s) |
Replaces "\’" with "\\\’" in s. |
replace(String s, String old, String new) |
Replaces all occurrences of old in the string s, with new. |
Examples:
<t:if test="toUpperCase('help')=='HELP'">toUpperCase success</t:if>
<t:if test="toLowerCase('HELP')=='help'">toLowerCase success</t:if>
<t:if test="toTitleCase('title')=='Title'">toTitleCase success</t:if>
<t:if test="toPlural('grow')=='grows'">toPlural success (s)</t:if>
<t:if test="toPlural('class')=='classes'">toPlural success (es)</t:if>
<t:if test="getDefault('','default')=='default'">getDefault success</t:if>
<t:if test="escapeQuotes('\'')=='\\\''">escapeQuotes success</t:if>
<t:if test="replace('Freely','ly','dom')=='Freedom'">replace success</t:if>
<t:if test="concat('Con','vio')=='Convio'">concat success</t:if>
<t:if test="substring('getactive', 3, 4)=='a'">substring success</t:if>
<t:if test="trim(' gooo ') == 'gooo'">trim success</t:if>
<t:if test="truncate('Alpahnumern',5)=='Al...'">truncate success</t:if>