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

# substring

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

## substring(text: String, from: Number, until: Number): String

Returns a substring that spans from the character at the specified `from` index to the last
character before the `until` index.

The characters in the substring satisfy the condition `from <= indexOf(string) < until`.

_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, treated as an array of characters.</p></td></tr><tr><td><p><code>from</code></p></td><td><p>The lowest index to include from the character array.</p></td></tr><tr><td><p><code>until</code></p></td><td><p>The lowest index to exclude from the character array.</p></td></tr></tbody></table>

### Example

This example returns the substring with characters at indices `1` through `4` in the input string.

#### Source

```DataWeave
%dw 2.0
import * from dw::core::Strings
output application/json
var text = "hello world!"
---
substring(text, 1, 5)
```

#### Output

```json
"ello"
```

## substring(text: Null, from: Any, until: Any): Null

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

_Introduced in DataWeave version 2.4.0._
