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

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