%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")
}
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.
Example
This example shows how prependIfMissing
behaves with different inputs and sizes.