Class StringUtils
String utility class.
| Constant | Description |
|---|---|
| ENCODE_TYPE_HTML: Number = 0 | String encoding type HTML. |
| String encoding type WML. | |
| ENCODE_TYPE_XML: Number = 1 | String encoding type XML. |
| TRUNCATE_CHAR: String = "char" | String truncate mode 'char'. |
| TRUNCATE_SENTENCE: String = "sentence" | String truncate mode 'sentence'. |
| TRUNCATE_WORD: String = "word" | String truncate mode 'word'. |
This class does not have a constructor, so you cannot create it directly.
| Method | Description |
|---|---|
| static decodeBase64(String) | Interprets a Base64 encoded string as byte stream of an UTF-8 encoded string. |
| static decodeBase64(String, String) | Interprets a Base64 encoded string as the byte stream representation of a string. |
| static decodeString(String, Number) | Convert a given syntax-safe string to a string according to the selected character entity encoding type. |
| static encodeBase64(String) | Encodes the byte representation of the given string as Base64. |
| static encodeBase64(String, String) | Encodes the byte representation of the given string as Base64. |
| static encodeString(String, Number) | Convert a given string to a syntax-safe string according to the selected character entity encoding type. |
| static format(String, Object...) | Returns a formatted string using the specified format and arguments. |
| static formatCalendar(Calendar) | Formats a Calendar object with Calendar.INPUT_DATE_TIME_PATTERN format of the current request locale, for example "MM/dd/yyyy h |
| static formatCalendar(Calendar, String) | Formats a Calendar object with the provided date format. |
| static formatCalendar(Calendar, String, Number) | Formats a Calendar object with the date format defined by the provided locale and Calendar pattern. |
| Formats a date with the default date format of the current site. | |
| Formats a date with the provided date format. | |
| Formats a date with the provided date format in specified locale. | |
| static formatInteger(Number) | Returns a formatted integer number using the default integer format of the current site. |
| static formatMoney(Money) | Formats a Money Object with the default money format of the current request locale. |
| static formatNumber(Number) | Returns a formatted number using the default number format of the current site. |
| static formatNumber(Number, String) | Returns a formatted string using the specified number and format. |
| static formatNumber(Number, String, String) | Returns a formatted number as a string using the specified number format in specified locale. |
| static formatNumber(Number, String) | Returns a formatted string using the specified number and format. |
| static formatNumber(Number, String, String) | Returns a formatted number as a string using the specified number format in specified locale. |
| static garble(String, String, Number) | Return a string in which specified number of characters in the suffix is not changed and the rest of the characters replaced with specified character. |
| static ltrim(String) | Returns the string with leading white space removed. |
| static pad(String, Number) | This method provides cell padding functionality to the template. |
| static rtrim(String) | Returns the string with trailing white space removed. |
| static stringToHtml(String) | Convert a given string to an HTML-safe string. |
| Converts a given string to a WML-safe string. | |
| static stringToXml(String) | Converts a given string to a XML-safe string. |
| static trim(String) | Returns the string with leading and trailing white space removed. |
| static truncate(String, Number, String, String) | Truncate the string to the specified length using specified truncate mode. |
assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values
- ENCODE_TYPE_HTML: Number = 0
String encoding type HTML.
See Also:
ENCODE_TYPE_WML: Number = 2String encoding type WML.
See Also:
Deprecated:
Don't use this constant anymore.
- ENCODE_TYPE_XML: Number = 1
String encoding type XML.
See Also:
- TRUNCATE_CHAR: String = "char"
String truncate mode 'char'. Truncate string to the nearest character. Default mode if no truncate mode is specified.
See Also:
- TRUNCATE_SENTENCE: String = "sentence"
String truncate mode 'sentence'. Truncate string to the nearest sentence.
See Also:
- TRUNCATE_WORD: String = "word"
String truncate mode 'word'. Truncate string to the nearest word.
See Also:
- static decodeBase64(base64: String): String
Interprets a Base64 encoded string as byte stream of an UTF-8 encoded string.
The method throws an IllegalArgumentException in case the encoding failed because of a mismatch between the input string and the character encoding.
Parameters:
- base64 - the Base64 encoded string - should not be empty or
null.
Returns:
- the decoded string.
- base64 - the Base64 encoded string - should not be empty or
- static decodeBase64(base64: String, characterEncoding: String): String
Interprets a Base64 encoded string as the byte stream representation of a string. The given character encoding is used for decoding the byte stream into the character representation.
The method throws an IllegalArgumentException in case the encoding failed because of a mismatch between the input String and the character encoding.
Parameters:
- base64 - the Base64 encoded string - should not be empty or
null. - characterEncoding - the character encoding to read the input string - should not be empty or
null.
Returns:
- the decoded string.
- base64 - the Base64 encoded string - should not be empty or
- static decodeString(str: String, type: Number): String
Convert a given syntax-safe string to a string according to the selected character entity encoding type.
Parameters:
- str - String to be decoded
- type - decode type
Returns:
- decoded string
- static encodeBase64(str: String): String
Encodes the byte representation of the given string as Base64. The string is converted into the byte representation with UTF-8 encoding.
The method throws an IllegalArgumentException in case the encoding failed because of a mismatch between the input string and the character encoding.
Parameters:
- str - the string to encode - should not be empty or
null.
Returns:
- the encoded string.
- str - the string to encode - should not be empty or
- static encodeBase64(str: String, characterEncoding: String): String
Encodes the byte representation of the given string as Base64. The string is converted into the byte representation using the given character encoding.
The method throws an IllegalArgumentException in case the encoding failed because of a mismatch between the input string and the character encoding.
Parameters:
- str - the string to encode - should not be empty or
null. - characterEncoding - the character encoding to read the input string - should not be empty or
null.
Returns:
- the encoded string.
- str - the string to encode - should not be empty or
- static encodeString(str: String, type: Number): String
Convert a given string to a syntax-safe string according to the selected character entity encoding type.
Parameters:
- str - String to be encoded
- type - encode type
Returns:
- encoded string
- static format(format: String, args: Object...): String
Returns a formatted string using the specified format and arguments. The formatting string is a Java MessageFormat expression, e.g. format( "Message: {0}, {1}", "test", 10 ) would result in "Message: test, 10".
If a Collection is passed as the only argument, the elements of this collection are used as arguments for the formatting.
Parameters:
- format - Java like formatting string.
- args - optional list of arguments or a collection, which are included into the result string
Returns:
- the formatted result string.
- static formatCalendar(calendar: Calendar): String
Formats a Calendar object with Calendar.INPUT_DATE_TIME_PATTERN format of the current request locale, for example "MM/dd/yyyy h
a" for the locale en_US. The used time zone is the time zone of the calendar object. Parameters:
- calendar - the calendar object.
Returns:
- a string representation of the formatted calendar object.
- static formatCalendar(calendar: Calendar, format: String): String
Formats a Calendar object with the provided date format. The format is a Java date format, like "yyy-MM-dd". The used time zone is the time zone of the calendar object.
Parameters:
- calendar - the calendar object to be printed
- format - the format to use.
Returns:
- a string representation of the formatted calendar object.
- static formatCalendar(calendar: Calendar, locale: String, pattern: Number): String
Formats a Calendar object with the date format defined by the provided locale and Calendar pattern. The locale can be for instance the request.getLocale(). The used time zone is the time zone of the calendar object.
Parameters:
- calendar - the calendar object to be printed
- locale - the locale, which defines the date format to be used
- pattern - the pattern is one of a calendar pattern e.g. SHORT_DATE_PATTERN as defined in the regional settings for the locale
Returns:
- a string representation of the formatted calendar object.
static formatDate(date: Date): StringFormats a date with the default date format of the current site.
Parameters:
- date - the date to format.
Returns:
- a string representation of the formatted date.
Deprecated:
Use formatCalendar(Calendar, String) instead.
static formatDate(date: Date, format: String): StringFormats a date with the provided date format. The format is the Java date format, like "yyyy-MM-DD". The locale of the calling context request is used in formatting.
Parameters:
- date - the date to format.
- format - the format to use.
Returns:
- a string representation of the formatted date.
Deprecated:
Use formatCalendar(Calendar, String) instead.
static formatDate(date: Date, format: String, locale: String): StringFormats a date with the provided date format in specified locale. The format is Java date format, like "yyyy-MM-DD".
Parameters:
- date - the date to format.
- format - the format to use.
- locale - the locale to use.
Returns:
- a string representation of the formatted date.
Deprecated:
Use formatCalendar(Calendar, String) instead.
- static formatInteger(number: Number): String
Returns a formatted integer number using the default integer format of the current site. The method can be also called to format a floating number as integer.
Parameters:
- number - the number to format.
Returns:
- a formatted an integer number with the default integer format of the current site.
- static formatMoney(money: Money): String
Formats a Money Object with the default money format of the current request locale.
Parameters:
- money - The Money instance that should be formatted.
Returns:
- The formatted String representation of the passed money. In case of an error the string 'N/A' is returned.
- static formatNumber(number: Number): String
Returns a formatted number using the default number format of the current site.
Decimal and grouping separators are used as specified in the locales regional settings.
Parameters:
- number - the number to format.
Returns:
- a formatted number using the default number format of the current site.
- static formatNumber(number: Number, format: String): String
Returns a formatted string using the specified number and format. The format is Java number format, like "#,###.00". To format as an integer number provide "0" as format string. The locale of the calling context request is used in formatting.
Parameters:
- number - the number to format.
- format - the format to use.
Returns:
- a formatted string using the specified number and format.
API Version:
No longer available as of version 18.10.
- static formatNumber(number: Number, format: String, locale: String): String
Returns a formatted number as a string using the specified number format in specified locale. The format is Java number format, like "#,###.00". To format as an integer number provide "0" as format string.
Parameters:
- number - the number to format.
- format - the format to use.
- locale - the locale to use.
Returns:
- a formatted number as a string using the specified number format in specified locale.
API Version:
No longer available as of version 18.10.
- static formatNumber(number: Number, format: String): String
Returns a formatted string using the specified number and format. The format is Java number format, like "#,###.00". To format as an integer number provide "0" as format string. The locale of the calling context request is used in formatting.
Decimal and grouping separators are used as specified in the locales regional settings (when configured, otherwise a fallback to the internal configuration is done).
Parameters:
- number - the number to format.
- format - the format to use.
Returns:
- a formatted string using the specified number and format.
API Version:
Available from version 18.10. In prior versions this method did fall back to Java formatting rules, instead of using the definitions in regional settings.
- static formatNumber(number: Number, format: String, locale: String): String
Returns a formatted number as a string using the specified number format in specified locale. The format is Java number format, like "#,###.00". To format as an integer number provide "0" as format string.
Decimal and grouping separators are used as specified in the locales regional settings (when configured, otherwise a fallback to the internal configuration is done).
Parameters:
- number - the number to format.
- format - the format to use.
- locale - the locale to use.
Returns:
- a formatted number as a string using the specified number format in specified locale.
API Version:
Available from version 18.10. In prior versions this method did fall back to Java formatting rules, instead of using the definitions in regional settings.
- static garble(str: String, replaceChar: String, suffixLength: Number): String
Return a string in which specified number of characters in the suffix is not changed and the rest of the characters replaced with specified character.
Parameters:
- str - String to garble
- replaceChar - character to use as a replacement
- suffixLength - length of the suffix
Returns:
- the garbled string.
- static ltrim(str: String): String
Returns the string with leading white space removed.
Parameters:
- str - the String to remove characters from.
Returns:
- the string with leading white space removed.
- static pad(str: String, width: Number): String
This method provides cell padding functionality to the template.
Parameters:
- str - the string to process
- width - The absolute value of this number defines the width of the cell. A possitive number forces left, a negative number right alignment. A '0' doesn't change the string.
Returns:
- the processed string.
- static rtrim(str: String): String
Returns the string with trailing white space removed.
Parameters:
- str - the String to remove characters from.
Returns:
- the string with trailing white space removed.
- static stringToHtml(str: String): String
Convert a given string to an HTML-safe string. This method substitutes characters that conflict with HTML syntax (<,>,&,") and characters that are beyond the ASCII chart (Unicode 160-255) to HTML 3.2 named character entities.
Parameters:
- str - String to be converted.
Returns:
- converted string.
static stringToWml(str: String): StringConverts a given string to a WML-safe string. This method substitutes characters that conflict with WML syntax (<,>,&,',"$) to WML named character entities.
Parameters:
- str - String to be converted.
Returns:
- the converted string.
Deprecated:
Don't use this method anymore
- static stringToXml(str: String): String
Converts a given string to a XML-safe string. This method substitutes characters that conflict with XML syntax (<,>,&,',") to XML named character entities.
Parameters:
- str - String to be converted.
Returns:
- the converted string.
- static trim(str: String): String
Returns the string with leading and trailing white space removed.
Parameters:
- str - the string to trim.
Returns:
- the string with leading and trailing white space removed.
- static truncate(str: String, maxLength: Number, mode: String, suffix: String): String
Truncate the string to the specified length using specified truncate mode. Optionally, append suffix to truncated string.
Parameters:
- str - string to truncate
- maxLength - maximum length of the truncated string, not including suffix
- mode - truncate mode (TRUNCATE_CHAR, TRUNCATE_WORD, TRUNCATE_SENTENCE), if null TRUNCATE_CHAR is assumed
- suffix - suffix append to the truncated string
Returns:
- the truncated string.