---
schema_version: "1"
id: a11d17d704c2af72e6228c8eb2da8720cbce75bc7684c779a05161b10adc4ab1
title: substringBy
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.12/dw-strings-functions-substringby.md
canonical_url: https://docs.mulesoft.com/dataweave/2.12/dw-strings-functions-substringby
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 0aac50af424fec20843390662f89c005404cf3d22f535e69e399821f757276da
description: MuleSoft Documentation Site
release: "2.12"
latest: false
---
---
product: DataWeave
version: 2.12
---

# substringBy

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## substringBy(text: String, predicate: (character: String, index: Number) -> Boolean): Array<String>

Splits a string at each character where the `predicate` expression returns `true`.

_Introduced in DataWeave version 2.4.0._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>text</code></p></td><td><p>The string to split. The string is treated as an array of characters.</p></td></tr><tr><td><p><code>predicate</code></p></td><td><p>Expression that tests each character and returns a Boolean value. The expression can iterate over each character and index of the string.</p></td></tr></tbody></table>

### Example

This example splits a string where any of the specified characters (`"~"`, `"="`, or `"_"`) are
present.

#### Source

```DataWeave
%dw 2.0
import substringBy from dw::core::Strings
output application/json
---
"hello~world=here_data-weave" substringBy $ == "~" or $ == "=" or $ == "_"
```

#### Output

```Json
["hello", "world", "here", "data-weave"]
```

## substringBy(text: Null, predicate: (character: Nothing, index: Nothing) -> Any): Null

Helper function that enables `substringBy` to work with a `null` value.

_Introduced in DataWeave version 2.4.0._
