%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/", '/')
}
wrapIfMissing
wrapIfMissing(text: String, wrapper: String): String
Wraps text
with wrapper
if that wrapper
is missing from the start or
end of the given string.
Introduced in DataWeave version 2.2.0.
Example
This example shows how wrapIfMissing
behaves with different inputs and sizes.