String Transformers
String transformers can be used on a value data type of string, including a string coming from other transformers, such as .first() item of an array. Following transformers are available:
lowercased
lowercasedReturns lowercased string:
Usage:
.lowercased()Example usage:
value.lowercased()Example:
Space Is Awesometospace is awesome
uppercased
uppercasedReturns uppercased string:
Usage:
.uppercased()Example usage:
value.uppercased()Example:
FalcontoFALCON
prefixed
prefixedReturns string prefixed with the given string. prefix must be a string value.
Usage:
.prefixed(prefix)Example usage:
value.prefixed("This")Example return:
valuetoThis value
suffixed
suffixedReturns string suffixed with the given suffix. suffix must be a string value.
Usage:
.suffixed(suffix)Example usage:
value.suffixed("That")Example return:
extendstoextends That
extended
extendedReturns string extended with prefix and suffix. prefix and suffix must both be string values.
Usage:
.extended(prefix, suffix)Example usage:
value.extended("This", "That")Example return:
extendstoThis extends That
capitalized
capitalizedReturns string with the first letter uppercased.
Usage:
.capitalized()Example usage:
value.capitalized()Example return:
this and thattoThis And That
snakecased
snakecasedReturns string in snake case representation.
Usage:
.snakecased()Example usage:
value.snakecased()Example return:
This and thattothis_and_that
camelcased
camelcasedReturns string in camel case representation. If isCapitalized is true, the first letter of the source is capitalized, otherwise lowercase letter returns.
Usage:
.camelcased(isCapitalized)Example usage:
value.camelcased(false)Example return:
This and thattothisAndThat
or
Example usage:
value.camelcased(true)Example return:
This and thattoThisAndThat
replacing
replacingReturns the source with all occurrences of provided substring replaced with another string. search and replace must both be String values.
Usage:
.replacing(search, replace)Example usage:
value.replacing("Tom", "John")Example return:
Tom is a boytoJohn is a boy
trimming
trimmingReturns the source with left and right-trimmed control character. value must be a string value.
Usage:
.trimming(value)Example usage:
value.trimming("o")Example return:
ouzotouz
trimmingSpaces
trimmingSpacesReturns the source with left and right-trimmed spaces.
Usage:
.trimmingSpaces()Example usage:
value.trimmingSpaces()Example return:
TomtoTom
slashNewlines
slashNewlinesReplaces all occurrences of newlines with \n character, producing a code-safe string.
Usage:
.slashNewlines()Example usage:
value.splashNewlines()Example return:
Tom is \n AwesometoTom is \\n Awesome
slashSingleQuotes
slashSingleQuotesReplaces all occurrences of ' with \' character, producing a code-safe string.
Usage:
.slashSingleQuotes()Example usage:
value.slashSingleQuotes()Example return:
Tom's hattoTom\'s hat
slashDoubleQuotes
slashDoubleQuotesReplaces all occurrences of " with \" character, producing a code-safe string.
Usage:
.slashDoubleQuotes()Example usage:
value.slashDoubleQuotes()Example return:
Tom's "hat"toTom's \"hat\"
split
splitReturns array of strings made by splitting the source using separator. separator can be multiple characters, must be a string.
Usage:
.split(separator)Example usage:
value.split("|")Example return:
this|that|thoseto["this", "that", "those"]
contains
containsReturns true if the string contains another substring, otherwise false. Case sensitive search.
Usage:
.contains(substring)Example usage:
value.contains("X")Example return:
"SpaceX"totrue
startsWith
startsWithReturns true if the beginning of the string is provided substring, otherwise false. Case sensitive search.
Usage:
.startsWith(substring)Example usage:
value.startsWith("S")Example return:
"SpaceX"totrue
endsWith
endsWithReturns true if the end of the string is provided substring, otherwise false. Case sensitive search.
Usage:
.endsWith(substring)Example usage:
value.startsWith("X")Example return:
"SpaceX"totrue
splitExpr
splitExprReturns array of strings made by splitting the source using expression. expression must be a valid regexp.
Usage:
.splitExpr(expression)Example usage:
value.split("\\s+")Example return:
this and thatto["this", "and", "that"]
splitNewlines
splitNewlinesReturns array of strings made by splitting the source using "\n".
Usage:
.splitNewlines()Example usage:
value.splitNewlinesExample return:
this\nthatto["this", "that"]
substring
substringReturns substring by initial location and length. location and length must be Int. When the location is out of bounds, an empty string is returned. When length + location is out of bounds, substring until the end of the original string will be returned.
Usage:
.substring(location, length)Example usage:
value.substring(1, 3)Example return:
wordstoord
default
defaultOutputs the default value if the source value is nil or empty. value must be a string value.
Usage:
.default(value)Example usage:
value.default("Empty")Example return:
niltoEmpty
count
countReturns the length of the string. Works well with things like emojis and other complex characters, properly counting them as one character.
Usage:
.count()Example usage:
value.count()Example return:
Bobto3
formatDate
formatDateOutputs formatted string which was created from the input date.
Note that the source value must be of ISO8601 format (either yyyy-MM-dd'T'HH:mm:ssZ or yyyy-MM-dd'T'HH:mm:ss.SSSZ is accepted).
Usage:
.formatDate(format)Example usage:
value.formatDate("YYYY-MM-DD")Example return:
2020-04-21T07:26:31.500Zto2020-04-21
Last updated
Was this helpful?