# 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: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
