Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fstring%2Fsubstr.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fstring%2Fsubstr.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `substr`

## Description

Extracts a substring from a string starting at a given position, with an optional length. Useful for simple value extraction without needing regular expressions.

## Syntax

Like many functions in DataPrime, `substr` supports<!-- --> [two notations](https://docs-docusaurus.kinsta.page/dataprime/language-reference/functions-reference/.md),<!-- --> **function** and **method**. These interchangeable forms allow flexibility in how you structure expressions.

* Function notation
* Method notation

```
substr(value: string, from: number, length?: number): string
```

```
(value: string).substr(from: number, length?: number): string
```

## Arguments

| Name     | Type     | Required  | Description                                                             |
| -------- | -------- | --------- | ----------------------------------------------------------------------- |
| `value`  | `string` | **true**  | The string to extract from                                              |
| `from`   | `number` | **true**  | The starting index for the substring                                    |
| `length` | `number` | **false** | Number of characters to return. Defaults to the remainder of the string |

## Example

**Extract the value after a delimiter**

Consider the following document:

```
{

    "msg": "result=Some value"

}
```

First, find the position of `=` with `indexOf`, then use `substr` to capture everything after it:

### Example query

* Function notation
* Method notation

```
create index_of_value from (indexOf(msg, '=') + 1)

| create value from substr(msg, index_of_value)
```

```
create index_of_value from (msg.indexOf('=') + 1)

| create value from msg.substr(index_of_value)
```

### Example output

```
{

    "msg": "result=Some value",

    "index_of_value": 7,

    "value": "Some value"

}
```
