- 2 minutes to read
Formula - substring
The substring Formula function returns length characters of the content, starting at the zero-based startIndex.
Syntax
substring(startIndex, length, content)
Parameters
| Parameter | Required | Description |
|---|---|---|
startIndex |
Yes | The zero-based position of the first character to return; 0 is the first character. Write it as a number, without quotes. |
length |
Yes | The number of characters to return. Write it as a number, without quotes. |
content |
Yes | The text to take characters from: body, context, or the result of another function, such as jsonPath. |
Returns
The part of the content from startIndex for length characters. When the content holds several values, each value is cut and returned as its own Search Field value.
Examples
Example 1: Take the first four characters of the message body
Input
nodinte
Formula
substring(0, 4, body)
Result
nodi

Start index 0 is the first character, so four characters from the start are returned.
Example 2: Take the first word of a context property
Input
| Key | Value |
|---|---|
id |
Amazing Function |
Formula
substring(0, 7, context('id'))
Result
Amazing

Seven characters from the start of the context value Amazing Function.
Example 3: Take the first two characters of several jsonPath values
Input
[
{ "name": "column" },
{ "name": "olive"}
]
Formula
substring(0, 2, jsonPath('$..name', body))
Result
co
ol

jsonPath returns two values, and substring cuts each one: two unique matches.