Contact Free trial Login


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.


Name Description


The input string.


The text to use as prefix.


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


%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")


  "a": null,
  "b": "abc",
  "c": "xyz",
  "d": "xyzabc",
  "e": "xyzabc"

prependIfMissing(Null, String): Null

Helper function to make prependIfMissing work with null value.

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.