Contact Us 1-800-596-4880

wrapWith

wrapWith(text: String, wrapper: String): String

Wraps the specified text with the given wrapper.

Introduced in DataWeave version 2.2.0.

Parameters

Name Description

text

The input string.

wrapper

The content used to wrap.

Example

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

Source

%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

{
  "a": null,
  "b": "''",
  "c": "xabx",
  "d": "''ab''",
  "e": "'ab'"
}

wrapWith(text: Null, wrapper: Any): Null

Helper function that enables wrapWith to work with a null value.

Introduced in DataWeave version 2.2.0.