> For the complete documentation index, see [llms.txt](https://documentation.astera.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.astera.com/astera-data-stack-v6/functions/string/lsplit-string.md).

# LSplit (String)

| **Name**    | ***LSplit***                                                                                                                                                                                                                                                                                                                                                                                                              |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Syntax      | LSplit (String str, Integer maxTokens, String delimiter, Integer returnToken)                                                                                                                                                                                                                                                                                                                                             |
| Purpose     | To split a string into chunks, specified by an integer value of a ‘maxTokens’ variable, and delimited by a ‘delimiter’ string value. Returns specified token at index ‘returnToken’, counting from the left. (**Note:** The integer value, 0, will return the first split chunk)                                                                                                                                          |
| Description | Splits a string into a maximum ‘maxTokens’ tokens delimited by ‘delimiter’. Returns token at index ‘returnToken’ counting from the left.                                                                                                                                                                                                                                                                                  |
| Return Type | String                                                                                                                                                                                                                                                                                                                                                                                                                    |
| Parameters  | <p>str \[System.String] – The string to be broken into tokens</p><p>maxTokens \[System.Int32] – The maximum number of tokens to split the string into. -1 is taken to unlimited. The number should be greater than the index of the token to be returned</p><p>delimiter \[System.String]</p><p>returnToken \[System.Int32] – The index (Counting from left to right) of the token generating by splitting the string</p> |

![](https://github.com/astera-software/Astera_Data_Stack_v9/blob/main/.gitbook/assets/0%20\(223\).png)

**Example**

We have a sample *Customers\_Marketing* dataset with the field *CompanyName.* In this example, we want to return the first part of each record in the *CompanyName* field.

![](https://github.com/astera-software/Astera_Data_Stack_v9/blob/main/.gitbook/assets/1%20\(223\).png)

We will use the *LSplit* function and a *Variables* object to do this. We will map the *CompanyName* field from our source object to the *str* input node of the function transformation object. For the other required inputs of the function transformation object, we will use a *Variables* object.

Where,

*maxTokens =* 2

{% hint style="info" %}
**Note:** As we only want to return the first part of the string, splitting the string into two chunks is sufficient for our case
{% endhint %}

*delimiter =*

{% hint style="info" %}
**Note:** Since the string values in our case are separated using a space, our delimiter value will also be a space. This value can be replaced with other delimiters, for example, “,”, depending on the data format
{% endhint %}

*returnToken* = 0

{% hint style="info" %}
**Note:** We are using the value 0, as we want to return the first part of the split string
{% endhint %}

![](https://github.com/astera-software/Astera_Data_Stack_v9/blob/main/.gitbook/assets/2%20\(221\).png)

We will write the output to a *Delimited Destination File* object.

![](https://github.com/astera-software/Astera_Data_Stack_v9/blob/main/.gitbook/assets/3%20\(43\).png)

Now, to view the output, we will right-click on the destination object’s header and select *Preview Output.* You can see that Astera Data Stack has split the string values in the *CompanyName* field, and returned only the first part of the split string.

![](https://github.com/astera-software/Astera_Data_Stack_v9/blob/main/.gitbook/assets/4%20\(8\).png)

Similarly, if we change the *returnToken* value to “1”, the second chunk from the two will be returned, as shown below:

![](https://github.com/astera-software/Astera_Data_Stack_v9/blob/main/.gitbook/assets/5%20\(2\)%20\(1\)%20\(1\).png)


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://documentation.astera.com/astera-data-stack-v6/functions/string/lsplit-string.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
