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 | str [System.String] – The string to be broken into tokens 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 delimiter [System.String] returnToken [System.Int32] – The index (Counting from left to right) of the token generating by splitting the string |
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2Fgithub.com%2Fastera-software%2FAstera_Data_Stack_v9%2Fblob%2Fmain%2F.gitbook%2Fassets%2F0%2520%28223%29.png&width=768&dpr=4&quality=100&sign=c99cb793&sv=1)
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://documentation.astera.com/~gitbook/image?url=https%3A%2F%2Fgithub.com%2Fastera-software%2FAstera_Data_Stack_v9%2Fblob%2Fmain%2F.gitbook%2Fassets%2F1%2520%28223%29.png&width=768&dpr=4&quality=100&sign=3617ee0a&sv=1)
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
Note: As we only want to return the first part of the string, splitting the string into two chunks is sufficient for our case
delimiter =
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
returnToken = 0
Note: We are using the value 0, as we want to return the first part of the split string
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2Fgithub.com%2Fastera-software%2FAstera_Data_Stack_v9%2Fblob%2Fmain%2F.gitbook%2Fassets%2F2%2520%28221%29.png&width=768&dpr=4&quality=100&sign=4aef76cb&sv=1)
We will write the output to a Delimited Destination File object.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2Fgithub.com%2Fastera-software%2FAstera_Data_Stack_v9%2Fblob%2Fmain%2F.gitbook%2Fassets%2F3%2520%2843%29.png&width=768&dpr=4&quality=100&sign=dfe704f2&sv=1)
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.
Similarly, if we change the returnToken value to “1”, the second chunk from the two will be returned, as shown below: