---
schema_version: "1"
id: 65aeacdfa6e33fd2363353e97ff948db972eea71ff4425392b451d9464c79acc
title: substringBy
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/latest/dw-strings-functions-substringby.md
canonical_url: https://docs.mulesoft.com/dataweave/latest/dw-strings-functions-substringby
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 52b30dba9d41e8842a8defc0c759fd7b7774cdab7abdc7f64a6a5c60473919fd
description: MuleSoft Documentation Site
release: "2.13"
latest: true
---
---
product: DataWeave
version: 2.13
is-latest-version: true
---

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