%dw 2.0
import collapse from dw::core::Strings
output application/json
---
collapse("a b babb a")
DataWeave
collapse
collapse(text: String): Array<String>
Collapses the string into substrings of equal characters.
Each substring contains a single character or identical characters that are adjacent to one another in the input string. Empty spaces are treated as characters.
Introduced in DataWeave version 2.4.0.
Parameters
Name | Description |
---|---|
|
The string to collapse. |
Example
This example shows how the function collapses characters. Notice that the empty space (" ") is treated as a character.
Source
Output
["a", " ", "b", " ", "b", "a", "bb", " ", "a"]
Json
collapse(text: Null): Null
Helper function that enables collapse
to work with a null
value.
Introduced in DataWeave version 2.4.0.