Contact Free trial Login

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

text

The input string.

wrapper

The content used to wrap.

Example

This example shows how wrapIfMissing behaves with different inputs and sizes.

Source

%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

{
   "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.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub