%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")
}
DataWeave
prependIfMissing
prependIfMissing(text: String, prefix: String): String
Prepends the prefix
to the beginning of the string if the text
does not
already start with that prefix.
Introduced in DataWeave version 2.2.0.
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
Output
{
"a": null,
"b": "abc",
"c": "xyz",
"d": "xyzabc",
"e": "xyzabc"
}
JSON
prependIfMissing(text: Null, prefix: String): Null
Helper function that enables prependIfMissing
to work with a null
value.
Introduced in DataWeave version 2.2.0.