> For the complete documentation index, see [llms.txt](https://docs.wem.io/platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wem.io/platform/wemreference/functions/text/substring.md).

# SubString

{% hint style="info" %}
The **`Substring()`** function returns a subset of a <mark style="color:blue;">text</mark>.&#x20;

This function is NOT SQL compatible. For more information about SQL compatibility, see our [documentation](/platform/wemreference/sql-compatibility.md).

WEM functions are 1-based where it concerns position parameters: 1 is the first position.
{% endhint %}

{% hint style="success" %}
Returns a new <mark style="color:green;">text</mark> that is a subset of <mark style="color:blue;">`text`</mark> beginning at a position through a number of characters. \
Returns <mark style="color:red;">`Invalid expression`</mark> if one of the parameters is not valid.&#x20;

If length-parameter is longer than the length of text, the result will be from the indicated start\_position until the last character.
{% endhint %}

### Syntax

<details>

<summary><code>Substring(</code><mark style="color:blue;"><code>text</code></mark><code>,</code><mark style="color:blue;"><code>length</code></mark><code>)</code></summary>

*If only the length parameter is provided, the result will be taken from the first character of the text-value.*&#x20;

`Substring("Important", 6)`\
\=> *"Import"* &#x20;

`Substring("Important", 16)`\
\=> *"Important"* &#x20;

</details>

<details>

<summary><code>Substring(</code><mark style="color:blue;"><code>text</code></mark><code>,</code><mark style="color:blue;"><code>start_position</code></mark><code>,</code><mark style="color:blue;"><code>length</code></mark><code>)</code></summary>

*If start\_position is specifically provided, the result will be taken from the indicated starting position with the understanding that position 1 is the first character.* \
*If 0 (zero) is used as start\_position, it will also use the first character to start from.*&#x20;

`Substring("Important", 3, 4)`\
\=> *"port"*

`Substring("Important", 1, 2)`\
\=> *"Im"*

`Substring("Important", 0, 2)`\
\=> *"Im"*

`Substring("Important", 4, 16)`\
\=> *"ortant"*

</details>

### Parameters

<table><thead><tr><th width="202.70825474075613">Name</th><th width="150">Type</th><th width="150" align="center">Required</th><th width="248.15953250810662">Description</th><th data-hidden>Required?</th></tr></thead><tbody><tr><td><mark style="color:blue;"><code>text</code></mark></td><td>text</td><td align="center"><span data-gb-custom-inline data-tag="emoji" data-code="2611">☑️</span></td><td>a text</td><td>yes</td></tr><tr><td><mark style="color:blue;"><code>start_position</code></mark></td><td>numeric</td><td align="center"></td><td>(<em>optional</em>) the position to start from. 1-based, so the first character is start_position 1.</td><td></td></tr><tr><td><mark style="color:blue;"><code>length</code></mark></td><td>numeric</td><td align="center"><span data-gb-custom-inline data-tag="emoji" data-code="2611">☑️</span></td><td>the number of characters to take from <code>text</code></td><td></td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.wem.io/platform/wemreference/functions/text/substring.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
