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
lowercased
Returns lowercased string:
Usage:
.lowercased()
Example usage:
value.lowercased()
Example:
Space Is Awesome
tospace is awesome
uppercased
uppercased
Returns uppercased string:
Usage:
.uppercased()
Example usage:
value.uppercased()
Example:
Falcon
toFALCON
prefixed
prefixed
Returns string prefixed with the given string. prefix
must be a string value.
Usage:
.prefixed(prefix)
Example usage:
value.prefixed("This")
Example return:
value
toThis value
suffixed
suffixed
Returns string suffixed with the given suffix
. suffix
must be a string value.
Usage:
.suffixed(suffix)
Example usage:
value.suffixed("That")
Example return:
extends
toextends That
extended
extended
Returns 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:
extends
toThis extends That
capitalized
capitalized
Returns string with the first letter uppercased.
Usage:
.capitalized()
Example usage:
value.capitalized()
Example return:
this and that
toThis And That
snakecased
snakecased
Returns string in snake case representation.
Usage:
.snakecased()
Example usage:
value.snakecased()
Example return:
This and that
tothis_and_that
camelcased
camelcased
Returns 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 that
tothisAndThat
or
Example usage:
value.camelcased(true)
Example return:
This and that
toThisAndThat
replacing
replacing
Returns 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 boy
toJohn is a boy
trimming
trimming
Returns 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:
ouzo
touz
trimmingSpaces
trimmingSpaces
Returns the source with left and right-trimmed spaces.
Usage:
.trimmingSpaces()
Example usage:
value.trimmingSpaces()
Example return:
Tom
toTom
slashNewlines
slashNewlines
Replaces all occurrences of newlines with \n character, producing a code-safe string.
Usage:
.slashNewlines()
Example usage:
value.splashNewlines()
Example return:
Tom is \n Awesome
toTom is \\n Awesome
slashSingleQuotes
slashSingleQuotes
Replaces all occurrences of '
with \' character, producing a code-safe string.
Usage:
.slashSingleQuotes()
Example usage:
value.slashSingleQuotes()
Example return:
Tom's hat
toTom\'s hat
slashDoubleQuotes
slashDoubleQuotes
Replaces 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
split
Returns 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|those
to["this", "that", "those"]
contains
contains
Returns 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
startsWith
Returns 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
endsWith
Returns 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
splitExpr
Returns 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 that
to["this", "and", "that"]
splitNewlines
splitNewlines
Returns array of strings made by splitting the source using "\n"
.
Usage:
.splitNewlines()
Example usage:
value.splitNewlines
Example return:
this\nthat
to["this", "that"]
substring
substring
Returns 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:
words
toord
default
default
Outputs 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:
nil
toEmpty
count
count
Returns 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:
Bob
to3
formatDate
formatDate
Outputs 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.500Z
to2020-04-21
Last updated
Was this helpful?