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

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