# `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://coralogix.com/docs/dataprime/language-reference/functions-reference/index.md), **function** and **method** notation. These interchangeable forms allow flexibility in how you structure expressions.

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

```dataprime
(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:

```json
{
    "msg": "result=Some value"
}
```

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

### Example query

```dataprime
create index_of_value from (indexOf(msg, '=') + 1)
| create value from substr(msg, index_of_value)
```

```dataprime
create index_of_value from (msg.indexOf('=') + 1)
| create value from msg.substr(index_of_value)
```

### Example output

```json
{
    "msg": "result=Some value",
    "index_of_value": 7,
    "value": "Some value"
}
```
