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.


Name Description


The string to collapse.


This example shows how the function collapses characters. Notice that the empty space (" ") is treated as a character.


%dw 2.0
import collapse from dw::core::Strings
output application/json
collapse("a  b babb a")


["a", "  ", "b", " ", "b", "a", "bb", " ", "a"]

collapse(text: Null): Null

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

Introduced in DataWeave version 2.4.0.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub
Submit your feedback!
Share your thoughts to help us build the best documentation experience for you!
Take our latest survey!