Contact Us 1-800-596-4880

repeat

repeat(text: String, times: Number): String

Repeats a text the number of specified times.

Introduced in DataWeave version 2.2.0.

Parameters

Name Description

text

The input string.

times

Number of times to repeat char. Negative is treated as zero.

Example

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

Source

%dw 2.0
import * from dw::core::Strings
output application/json
---
{
  "a": repeat("e", 0),
  "b": repeat("e", 3),
  "c": repeat("e", -2)
}

Output

{
  "a": "",
  "b": "eee",
  "c": ""
}

repeat(text: Null, times: Any): Null

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

Introduced in DataWeave version 2.4.0.