# TextBetween - script and chart function

TextBetween() returns the text in the input string that occurs between the characters specified as delimiters.

Syntax:

TextBetween(text, delimiter1, delimiter2[, n])

Return data type: string

Arguments:

| Argument | Description |
| --- | --- |
| text | The original string. |
| delimiter1 | Specifies the first delimiting character (or string) to search for in text. |
| delimiter2 | Specifies the second delimiting character (or string) to search for in text. |
| n | Defines which occurrence of the delimiter pair to search between. For example, a value of 2 returns the characters between the second occurrence of delimiter1 and the second occurrence of delimiter2. |

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/TextBetween.htm)

#### Example: Chart expressions

| Example | Result |
| --- | --- |
| `TextBetween('<abc>',<br>			'<', '>')` | Returns 'abc' |
| `TextBetween('<abc><de>',<br>'<', '>',2)` | Returns 'de' |
| `TextBetween('abc', '<', '>')`<br><br>`TextBetween('<a<b', '<', '>')` | Both examples return NULL.<br><br>If any of the delimiter is not found in the string, NULL is returned. |
| `TextBetween('<>',<br>			'<', '>')` | Returns a zero-length string. |
| `TextBetween('<abc>',<br>			'<', '>', 2)` | Returns NULL, as n is greater than the number of occurrences of the delimiters. |

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/TextBetween.htm)

#### Example: Load script

```
Load *,
textbetween(Text,'<','>') as TextBetween,
textbetween(Text,'<','>',2) as SecondTextBetween;
Load * inline [
Text
<abc><de>
<def><ghi><jkl> ];
```

Result

| Text | TextBetween | SecondTextBetween |
| --- | --- | --- |
| &lt;abc&gt;&lt;de&gt; | abc | de |
| &lt;def&gt;&lt;ghi&gt;&lt;jkl&gt; | def | ghi |