LSplit (String)

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.

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

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

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: