> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.itential.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.itential.com/_mcp/server.

# substring

> Use the substring task to extract a sequence of characters from a string between a start and end index.

The `substring` task extracts a contiguous sequence of characters from a string between a specified start and end index (or to the end of the string) and returns a new `substring`. The original string is not modified.

## Potential use case

Because `substring` returns a new string containing the extracted characters, you can use it to extract only the telephone area code from an incoming string of phone number data.

## Properties

| Incoming     | Type   | Description                                                                                                                                           |
| :----------- | :----- | :---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `str`        | String | Required. The string containing the substring to extract.                                                                                             |
| `indexStart` | Number | Required. The position in the string to begin extraction. Indexing is zero-based (defaults to `0`).                                                   |
| `indexEnd`   | Number | Optional. The position up to (but not including) where extraction stops. If not specified, the task extracts all characters to the end of the string. |

If `indexEnd` is less than `indexStart`, the effect is to swap the two values. If you need to return a blank value instead, see the `splice` (string) task.

| Outgoing   | Type   | Description              |
| :--------- | :----- | :----------------------- |
| `response` | String | The extracted substring. |

## Example 1

In this example:

* The `str` is statically set to `800-555-1212`.
* The `indexStart` is `0`.
* The `indexEnd` is `3`, so extraction stops before character position three (the first hyphen `"-"`).
* The `substring` output is `800`.

![](/_fern-img/6938f3db769cd9b8de44900b70b60b79e664ca90f9647c0a6862f91c76d19f5a.webp)

## Example 2

In this example:

* The `str` is statically set to `800-555-1212`.
* The `indexStart` is `4`.
* The `indexEnd` is `7`, so extraction stops before character position seven (the second hyphen `"-"`).
* The `substring` output is `555`.

![](/_fern-img/216b97f40e18ba858a5346afee4ecf60897e92ca8efcafd24b435c8bc4148539.webp)