This module contains helper functions to work with Strings.
To use this module, you must import it to your DataWeave code, for example,
by adding the line import * from dw::core::Strings
to the header of your
DataWeave script.
Functions
appendIfMissing
appendIfMissing(String, String): String
Appends the suffix
to the end of the text
if the text
does not already
ends with the suffix
.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
|
The text used as the suffix. |
Example
This example shows how appendIfMissing
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
%dw 2.0
import appendIfMissing from dw::core::Strings
output application/json
---
{
"a": appendIfMissing(null, ""),
"b": appendIfMissing("abc", ""),
"c": appendIfMissing("", "xyz") ,
"d": appendIfMissing("abc", "xyz") ,
"e": appendIfMissing("abcxyz", "xyz")
}
Output
1
2
3
4
5
6
7
{
"a": null,
"b": "abc",
"c": "xyz",
"d": "abcxyz",
"e": "abcxyz"
}
appendIfMissing(Null, String): Null
Helper function that enables appendIfMissing
to work with a null
value.
camelize
camelize(String): String
Returns a string in camel case based on underscores in the string.
All underscores are deleted, including any underscores at the beginning of the string.
Parameters
Name | Description |
---|---|
|
The string to convert to camel case. |
Example
This example converts a string that contains underscores to camel case.
Source
1
2
3
4
5
6
7
8
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"a" : camelize("customer_first_name"),
"b" : camelize("_name_starts_with_underscore")
}
Output
1
2
3
4
{
"a": "customerFirstName",
"b": "nameStartsWithUnderscore"
}
camelize(Null): Null
Helper function that enables camelize
to work with a null
value.
capitalize
capitalize(String): String
Capitalizes the first letter of each word in a string.
It also removes underscores between words and puts a space before each capitalized word.
Parameters
Name | Description |
---|---|
|
The string to capitalize. |
Example
This example capitalizes a set of strings.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"a" : capitalize("customer"),
"b" : capitalize("customer_first_name"),
"c" : capitalize("customer NAME"),
"d" : capitalize("customerName")
}
Output
1
2
3
4
5
6
{
"a": "Customer",
"b": "Customer First Name",
"c": "Customer Name",
"d": "Customer Name"
}
capitalize(Null): Null
Helper function that enables capitalize
to work with a null
value.
charCode
charCode(String): Number
Returns the Unicode for the first character in an input string.
For an empty string, the function fails and returns Unexpected empty string
.
Parameters
Name | Description |
---|---|
|
The input string. |
Example
This example returns Unicode for the "M" in "Mule".
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"charCode" : charCode("Mule")
}
Output
1
{ "charCode" : 77 }
charCodeAt
charCodeAt(String, Number): Number
Returns the Unicode for a character at the specified index.
This function fails if the index is invalid.
Parameters
Name | Description |
---|---|
|
The input string. |
|
The index (a |
Example
This example returns Unicode for the "u" at index 1
in "MuleSoft".
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"charCodeAt" : charCodeAt("MuleSoft", 1)
}
Output
1
{ "charCodeAt": 117 }
dasherize
dasherize(String): String
Replaces spaces, underscores, and camel-casing in a string with dashes (hyphens).
If no spaces, underscores, and camel-casing are present, the output will match the input.
Parameters
Name | Description |
---|---|
|
The input string. |
Example
This example replaces the spaces, underscores, and camel-casing in the input. Notice that the input "customer" is not modified in the output.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"a" : dasherize("customer"),
"b" : dasherize("customer_first_name"),
"c" : dasherize("customer NAME"),
"d" : dasherize("customerName")
}
Output
1
2
3
4
5
6
{
"a": "customer",
"b": "customer-first-name",
"c": "customer-name",
"d": "customer-name"
}
dasherize(Null): Null
Helper function that enables dasherize
to work with a null
value.
fromCharCode
fromCharCode(Number): String
Returns a character that matches the specified Unicode.
Parameters
Name | Description |
---|---|
|
The input Unicode (a |
Example
This example inputs the Unicode number 117
to return the character "u".
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"fromCharCode" : fromCharCode(117)
}
Output
1
{ "fromCharCode": "u" }
isAlpha
isAlpha(String): Boolean
Checks if the text
contains only Unicode digits. A decimal point is not a Unicode digit and returns false
.
Note that the method does not allow for a leading sign, either positive or negative.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
Example
This example shows how isAlpha
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
12
%dw 2.0
import isAlpha from dw::core::Strings
output application/json
---
{
"a": isAlpha(null),
"b": isAlpha(""),
"c": isAlpha(" "),
"d": isAlpha("abc"),
"e": isAlpha("ab2c"),
"f": isAlpha("ab-c")
}
Output
1
2
3
4
5
6
7
8
{
"a": false,
"b": false,
"c": false,
"d": true,
"e": false,
"f": false
}
isAlpha(Null): Boolean
Helper function that enables isAlpha
to work with a null
value.
isAlphanumeric
isAlphanumeric(String): Boolean
Checks if the text
contains only Unicode letters or digits.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
Example
This example shows how isAlphanumeric
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
12
13
%dw 2.0
import isAlphanumeric from dw::core::Strings
output application/json
---
{
"a": isAlphanumeric(null),
"b": isAlphanumeric(""),
"c": isAlphanumeric(" "),
"d": isAlphanumeric("abc"),
"e": isAlphanumeric("ab c"),
"f": isAlphanumeric("ab2c"),
"g": isAlphanumeric("ab-c")
}
Output
1
2
3
4
5
6
7
8
9
{
"a": false,
"b": false,
"c": false,
"d": true,
"e": false,
"f": true,
"g": false
}
isAlphanumeric(Null): Boolean
Helper function that enables isAlphanumeric
to work with a null
value.
isLowerCase
isLowerCase(String): Boolean
Checks if the text
contains only lowercase characters.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
Example
This example shows how isLowerCase
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
%dw 2.0
import isLowerCase from dw::core::Strings
output application/json
---
{
"a": isLowerCase(null),
"b": isLowerCase(""),
"c": isLowerCase(" "),
"d": isLowerCase("abc"),
"e": isLowerCase("aBC"),
"f": isLowerCase("a c"),
"g": isLowerCase("a1c"),
"h": isLowerCase("a/c")
}
Output
1
2
3
4
5
6
7
8
9
10
{
"a": false,
"b": false,
"c": false,
"d": true,
"e": false,
"f": false,
"g": false,
"h": false
}
isLowerCase(Null): Boolean
Helper function that enables isLowerCase
to work with a null
value.
isNumeric
isNumeric(String): Boolean
Checks if the text
contains only Unicode digits.
A decimal point is not a Unicode digit and returns false. Note that the method does not allow for a leading sign, either positive or negative.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
Example
This example shows how isNumeric
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
%dw 2.0
import isNumeric from dw::core::Strings
output application/json
---
{
"a": isNumeric(null),
"b": isNumeric(""),
"c": isNumeric(" "),
"d": isNumeric("123"),
"e": isNumeric("१२३"),
"f": isNumeric("12 3"),
"g": isNumeric("ab2c"),
"h": isNumeric("12-3"),
"i": isNumeric("12.3"),
"j": isNumeric("-123"),
"k": isNumeric("+123")
}
Output
1
2
3
4
5
6
7
8
9
10
11
12
13
{
"a": false,
"b": false,
"c": false,
"d": true,
"e": true,
"f": false,
"g": false,
"h": false,
"i": false,
"j": false,
"k": false
}
isNumeric(Null): Boolean
Helper function that enables isNumeric
to work with a null
value.
isUpperCase
isUpperCase(String): Boolean
Checks if the text
contains only uppercase characters.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
Example
This example shows how isUpperCase
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
%dw 2.0
import isUpperCase from dw::core::Strings
output application/json
---
{
"a": isUpperCase(null),
"b": isUpperCase(""),
"c": isUpperCase(" "),
"d": isUpperCase("ABC"),
"e": isUpperCase("aBC"),
"f": isUpperCase("A C"),
"g": isUpperCase("A1C"),
"h": isUpperCase("A/C")
}
Output
1
2
3
4
5
6
7
8
9
10
{
"a": false,
"b": false,
"c": false,
"d": true,
"e": false,
"f": false,
"g": false,
"h": false
}
isUpperCase(Null): Boolean
Helper function that enables isUpperCase
to work with a null
value.
isWhitespace
isWhitespace(String): Boolean
Checks if the text
contains only whitespace.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
Example
This example shows how isWhitespace
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
12
%dw 2.0
import isWhitespace from dw::core::Strings
output application/json
---
{
"a": isWhitespace(null),
"b": isWhitespace(""),
"c": isWhitespace(" "),
"d": isWhitespace("abc"),
"e": isWhitespace("ab2c"),
"f": isWhitespace("ab-c")
}
Output
1
2
3
4
5
6
7
8
{
"a": false,
"b": true,
"c": true,
"d": false,
"e": false,
"f": false
}
isWhitespace(Null): Boolean
Helper function that enables isWhitespace
to work with a null
value.
leftPad
leftPad(String, Number, String): String
The specified text
is left-padded to the size
using the padText
.
By default padText
is " "
.
Returns left-padded String
or original String
if no padding is necessary.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
|
The size to pad to. |
|
The text to pad with. It defaults to one space if not specified. |
Example
This example shows how leftPad
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"a": leftPad(null, 3),
"b": leftPad("", 3),
"c": leftPad("bat", 5),
"d": leftPad("bat", 3),
"e": leftPad("bat", -1)
}
Output
1
2
3
4
5
6
7
{
"a": null,
"b": " ",
"c": " bat",
"d": "bat",
"e": "bat"
}
leftPad(Null, Number, String): Null
Helper function that enables leftPad
to work with a null
value.
ordinalize
ordinalize(Number): String
Returns a number as an ordinal, such as 1st
or 2nd
.
Parameters
Name | Description |
---|---|
|
An input number to return as an ordinal. |
Example
This example returns a variety of input numbers as ordinals.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"a" : ordinalize(1),
"b": ordinalize(2),
"c": ordinalize(5),
"d": ordinalize(103)
}
Output
1
2
3
4
5
6
{
"a": "1st",
"b": "2nd",
"c": "5th",
"d": "103rd"
}
ordinalize(Null): Null
Helper function that enables ordinalize
to work with a null
value.
pluralize
pluralize(String): String
Pluralizes a singular string.
If the input is already plural (for example, "boxes"), the output will match the input.
Parameters
Name | Description |
---|---|
|
The string to pluralize. |
Example
This example pluralizes the input string "box" to return "boxes".
Source
1
2
3
4
5
%dw 2.0
import * from dw::core::Strings
output application/json
---
{ "pluralize" : pluralize("box") }
Output
1
{ "pluralize" : "boxes" }
pluralize(Null): Null
Helper function that enables pluralize
to work with a null
value.
prependIfMissing
prependIfMissing(String, String): String
Prepends the prefix
to the beginning of the string if the text
does not
already start with that prefix.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
|
The text to use as prefix. |
Example
This example shows how prependIfMissing
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
%dw 2.0
import prependIfMissing from dw::core::Strings
output application/json
---
{
"a": prependIfMissing(null, ""),
"b": prependIfMissing("abc", ""),
"c": prependIfMissing("", "xyz"),
"d": prependIfMissing("abc", "xyz"),
"e": prependIfMissing("xyzabc", "xyz")
}
Output
1
2
3
4
5
6
7
{
"a": null,
"b": "abc",
"c": "xyz",
"d": "xyzabc",
"e": "xyzabc"
}
prependIfMissing(Null, String): Null
Helper function that enables prependIfMissing
to work with a null
value.
repeat
repeat(String, Number): String
Repeats a text
the number of specified times
.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
|
Number of times to repeat char. Negative is treated as zero. |
Example
This example shows how repeat
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"a": repeat("e", 0),
"b": repeat("e", 3),
"c": repeat("e", -2)
}
Output
1
2
3
4
5
{
"a": "",
"b": "eee",
"c": ""
}
replaceAll
replaceAll(String, String, String): String
Replaces each substring of text
String that matches the literal target
String with the specified literal replacement
String.
The replacement proceeds from the beginning of the string to the end, for example, replacing "aa" with "b" in the string "aaa" will result in "ba" rather than "ab".
Introduced in DataWeave 2.4.0. Supported by Mule 4.4 and later.
Parameters
Name | Description |
---|---|
text |
The text where to replace |
target |
The text to be search |
replacement |
The string to be substituted for each match |
Example
This example shows how the replaceAll
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
9
import * from dw::core::Strings
output application/json
---
{
a: replaceAll("Mariano", "a" , "A"),
b: replaceAll("AAAA", "AAA" , "B"),
c: replaceAll(null, "aria" , "A"),
d: replaceAll("Mariano", "j" , "Test"),
}
Output
1
2
3
4
5
6
{
"a": "MAriAno",
"b": "BA",
"c": null,
"d": "Mariano"
}
replaceAll(Null, String, String): Null
Helper function to make replaceAll work with null
Introduced in DataWeave 2.3.0. Supported by Mule 4.3 and later.
reverse
reverse(String): String
Returns the reverse sequence of characters of the given text
Introduced in DataWeave 2.3.0. Supported by Mule 4.3 and later.
Parameters
Name | Description |
---|---|
text |
The text to be reverse |
Example
This example shows how the reverse
behaves under different inputs.
Source
1
2
3
4
5
6
7
8
9
10
11
%dw 2.0
output application/json
---
import * from dw::core::Strings
output application/json
---
{
a: reverse("Mariano"),
b: reverse(null),
c: reverse("")
}
Output
1
2
3
4
5
{
"a": "onairaM",
"b": null,
"c": ""
}
reverse(Null): Null
Helper function to make reverse null friendly.
Introduced in DataWeave 2.3.0. Supported by Mule 4.3 and later.
rightPad
rightPad(String, Number, String): String
The specified text
is right-padded to the size
using the padText
.
By default padText
is " "
.
Returns right padded String
or original String
if no padding is necessary.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
|
The size to pad to. |
|
The text to pad with. It defaults to one space if not specified. |
Example
This example shows how rightPad
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"a": rightPad(null, 3),
"b": rightPad("", 3),
"c": rightPad("bat", 5),
"d": rightPad("bat", 3),
"e": rightPad("bat", -1)
}
Output
1
2
3
4
5
6
7
{
"a": null,
"b": " ",
"c": "bat ",
"d": "bat",
"e": "bat"
}
rightPad(Null, Number, String): Null
Helper function that enables rightPad
to work with a null
value.
singularize
singularize(String): String
Converts a plural string to its singular form.
If the input is already singular (for example, "box"), the output will match the input.
Parameters
Name | Description |
---|---|
|
The string to convert to singular form. |
Example
This example converts the input string "boxes" to return "box".
Source
1
2
3
4
5
%dw 2.0
import * from dw::core::Strings
output application/json
---
{ "singularize" : singularize("boxes") }
Output
1
{ "singularize" : "box" }
singularize(Null): Null
Helper function that enables singularize
to work with a null
value.
substringAfter
substringAfter(String, String): String
Gets the substring after the first occurrence of a separator. The separator is not returned.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
|
String to search for. |
Example
This example shows how substringAfter
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
12
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"a": substringAfter(null, "'"),
"b": substringAfter("", "-"),
"c": substringAfter("abc", "b"),
"d": substringAfter("abcba", "b"),
"e": substringAfter("abc", "d"),
"f": substringAfter("abc", "")
}
Output
1
2
3
4
5
6
7
8
9
{
"a": null,
"b": "",
"c": "c",
"d": "cba",
"e": "",
"f": "bc"
}
substringAfter(Null, String): Null
Helper function that enables substringAfter
to work with a null
value.
substringAfterLast
substringAfterLast(String, String): String
Gets the substring after the last occurrence of a separator. The separator is not returned.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
|
String to search for. |
Example
This example shows how substringAfterLast
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
12
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"a": substringAfterLast(null, "'"),
"b": substringAfterLast("", "-"),
"c": substringAfterLast("abc", "b"),
"d": substringAfterLast("abcba", "b"),
"e": substringAfterLast("abc", "d"),
"f": substringAfterLast("abc", "")
}
Output
1
2
3
4
5
6
7
8
{
"a": null,
"b": "",
"c": "c",
"d": "a",
"e": "",
"f": null
}
substringAfterLast(Null, String): Null
Helper function that enables substringAfterLast
to work with a null
value.
substringBefore
substringBefore(String, String): String
Gets the substring before the first occurrence of a separator. The separator is not returned.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
|
String to search for. |
Example
This example shows how substringBefore
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
12
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"a": substringBefore(null, "'"),
"b": substringBefore("", "-"),
"c": substringBefore("abc", "b"),
"d": substringBefore("abc", "c"),
"e": substringBefore("abc", "d"),
"f": substringBefore("abc", "")
}
Output
1
2
3
4
5
6
7
8
{
"a": null,
"b": "",
"c": "a",
"d": "ab",
"e": "",
"f": ""
}
substringBefore(Null, String): Null
Helper function that enables substringBefore
to work with a null
value.
substringBeforeLast
substringBeforeLast(String, String): String
Gets the substring before the last occurrence of a separator. The separator is not returned.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
|
String to search for. |
Example
This example shows how substringBeforeLast
behaves with different inputs
and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
12
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"a": substringBeforeLast(null, "'"),
"b": substringBeforeLast("", "-"),
"c": substringBeforeLast("abc", "b"),
"d": substringBeforeLast("abcba", "b"),
"e": substringBeforeLast("abc", "d"),
"f": substringBeforeLast("abc", "")
}
Output
1
2
3
4
5
6
7
8
{
"a": null,
"b": "",
"c": "a",
"d": "abc",
"e": "",
"f": "ab"
}
substringBeforeLast(Null, String): Null
Helper function that enables substringBeforeLast
to work with a null
value.
underscore
underscore(String): String
Replaces hyphens, spaces, and camel-casing in a string with underscores.
If no hyphens, spaces, and camel-casing are present, the output will match the input.
Parameters
Name | Description |
---|---|
|
The input string. |
Example
This example replaces the hyphens and spaces in the input. Notice that the input "customer" is not modified in the output.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"a" : underscore("customer"),
"b" : underscore("customer-first-name"),
"c" : underscore("customer NAME"),
"d" : underscore("customerName")
}
Output
1
2
3
4
5
6
{
"a": "customer",
"b": "customer_first_name",
"c": "customer_name",
"d": "customer_name"
}
underscore(Null): Null
Helper function that enables underscore
to work with a null
value.
unwrap
unwrap(String, String): String
Unwraps a given text
from a wrapper
text.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
|
The text used to unwrap. |
Example
This example shows how unwrap
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
12
13
%dw 2.0
import unwrap from dw::core::Strings
output application/json
---
{
"a": unwrap(null, ""),
"b": unwrap(null, '\0'),
"c": unwrap("'abc'", "'"),
"d": unwrap("AABabcBAA", 'A'),
"e": unwrap("A", '#'),
"f": unwrap("#A", '#'),
"g": unwrap("A#", '#')
}
Output
1
2
3
4
5
6
7
8
9
{
"a": null,
"b": null,
"c": "abc",
"d": "ABabcBA",
"e": "A",
"f": "A#",
"g": "#A"
}
unwrap(Null, String): Null
Helper function that enables unwrap
to work with a null
value.
withMaxSize
withMaxSize(String, Number): String
Checks that the string length is no larger than the specified maxLength
.
If the string’s length is larger than the maxLength
, the function cuts
characters from left to right, until the string length meets the length limit.
Introduced in DataWeave 2.3.0. Supported by Mule 4.3 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
|
The maximum length of the string. |
Example
This example shows how withMaxSize
behaves with different inputs and sizes.
Note that if withMaxSize
is 0, the function returns an empty string. If
the input is null
, the output is always null
.
Source
1
2
3
4
5
6
7
8
9
10
11
%dw 2.0
import withMaxSize from dw::core::Strings
output application/json
---
{
a: "123" withMaxSize 10,
b: "123" withMaxSize 3,
c: "123" withMaxSize 2,
d: "" withMaxSize 0,
e: null withMaxSize 23,
}
Output
1
2
3
4
5
6
7
{
"a": "123",
"b": "123",
"c": "12",
"d": "",
"e": null
}
withMaxSize(Null, Number): Null
Helper function that enables withMaxSize
to work with a null
value.
wrapIfMissing
wrapIfMissing(String, String): String
Wraps text
with wrapper
if that wrapper
is missing from the start or
end of the given string.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
|
The content used to wrap. |
Example
This example shows how wrapIfMissing
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"a": wrapIfMissing(null, "'"),
"b": wrapIfMissing("", "'"),
"c": wrapIfMissing("ab", "x"),
"d": wrapIfMissing("'ab'", "'"),
"e": wrapIfMissing("/", '/'),
"f": wrapIfMissing("a/b/c", '/'),
"g": wrapIfMissing("/a/b/c", '/'),
"h": wrapIfMissing("a/b/c/", '/')
}
Output
1
2
3
4
5
6
7
8
9
10
{
"a": null,
"b": "'",
"c": "xabx",
"d": "'ab'",
"e": "/",
"f": "/a/b/c/",
"g": "/a/b/c/",
"h": "/a/b/c/"
}
wrapIfMissing(Null, String): Null
Helper function that enables wrapIfMissing
to work with a null
value.
wrapWith
wrapWith(String, String): String
Wraps the specified text
with the given wrapper
.
Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.
Parameters
Name | Description |
---|---|
|
The input string. |
|
The content used to wrap. |
Example
This example shows how wrapWith
behaves with different inputs and sizes.
Source
1
2
3
4
5
6
7
8
9
10
11
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
"a": wrapWith(null, "'"),
"b": wrapWith("", "'"),
"c": wrapWith("ab", "x"),
"d": wrapWith("'ab'", "'"),
"e": wrapWith("ab", "'")
}
Output
1
2
3
4
5
6
7
{
"a": null,
"b": "''",
"c": "xabx",
"d": "''ab''",
"e": "'ab'"
}
wrapWith(Null, String): Null
Helper function that enables wrapWith
to work with a null
value.