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

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