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

# 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._
