Contact Us 1-800-596-4880

substring

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

Name Description

text

The string, treated as an array of characters.

from

The lowest index to include from the character array.

until

The lowest index to exclude from the character array.

Example

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

Source

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

Output

"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.