DataWeave Delight: Repeating a string value
The Strings
module in DataWeave has some very useful functions to work with string values. For example to repeat a string value we can use the repeat
function. The first argument is the string value we want to repeat and the second argument the number of times the value must be repeated.
In the following example we use the repeat
function to get 20 asterisks:
Source
%dw 2.0
import repeat from dw::core::Strings
output text/plain
---
repeat("*", 20)
Output
********************
The string value can also be more than one character:
Source
%dw 2.0
import repeat from dw::core::Strings
output text/plain
---
repeat("mrhaki ", 5)
Output
mrhaki mrhaki mrhaki mrhaki mrhaki
Written with DataWeave 2.4
DataWeave is a functional language designed by MuleSoft for transforming data structures defined in for example JSON, XML or CSV. |