< class="prominent-subhead ">

Splitting Text Using Expressions

This article was created in response to a support issue logged with K2. The content may include typographical errors and may be revised at any time without notice. This article is not considered official documentation for K2 software and is provided "as is" with no warranties.
This article has been archived, and/or refers to legacy products, components or features. The content in this article is offered "as is" and will no longer be updated. Archived content is provided for reference purposes only. This content does not infer that the product, component or feature is supported, or that the product, component or feature will continue to function as described herein.


This article shows you how to split text that has been pulled from a SmartObject, to be displayed in a control in the format T1;T2;T3; We will be cutting each of these into sections of text using expressions in order to add each section to its own control.

For example: Datalabel 1= T1    |    Datalabel 2 = T2    |    Datalabel3 = T3

Before You Begin

In this specific scenario we used a record with three values separated by semicolons in a single column, these values will be split and each value will be displayed in its own control.

There is no out of the box split method as there is no operator that can determine where to split text based on a certain string. This can however be built by using some expressions, the expression building will be somewhat complicated.

Based on this scenario it will always just return three values. There are some alterations you would need to make to the saved data as well as to your current expressions in order to split the content contained in the string values, especially when one of the values has been removed.

  • Ensure that when your values are saved that they end in a semicolon as well, the expressions will find the semicolons and split the values based on that, therefore the saved value should look like this: T1;T2;T3;
  • If there are spaces added between the semicolon and the next value, the expression might not behave as expected. Therefore, you need to ensure that there are no spaces added to the saved value.
  • This solution will also work if there are less than three values provided.
  • If you change the value yourself for testing purposes then you will need to remove the semicolon that goes with that value as well.

    : the value being returned from the SmartObject is "T1;T2;T3;" If you wanted to change the value to see if it still displays the correct result after i.e. T1; had been removed then you will need to remove the semicolon that goes with T1 as well.

How-to Steps

1. Build\configure the following expressions:

Explanation of the controls used in the expressions (to avoid expression building confusion):

  • R1(TB) - This is a textbox and contains the entire string that had been saved (this is the data that we will be splitting).
  • When a replace is done in the above expression, the "Empty String" operator is used as the replacing value.

2. After configuring the above expressions, bind them in the following order to the relevant control:

Datalabel 1 = Expression "Find T1"

Datalabel 2 = Expression "Find T2"

Datalabel 3 = Expression "Find T3"

3. At this stage your expressions will already have split the value from the control R1(TB), however the values will still have the semicolon appended to it. You need to remove it before displaying the result in the text boxes.

4. To remove the semicolons from the split values now displayed in datalabels, you should bind the "Remove Semicolon" expressions to the relevant control (in this case, text boxes) as per below:

Text Box 1 = Expression "Remove Semicolon T1"
Text Box 2 = Expression "Remove Semicolon T2"

Text Box 3 = Expression "Remove Semicolon T3"

5. Next, your result will look like the image below. When you remove the first value from the R1 (TB) control which contains the initial value, the expressions will execute again and return the correct results:

The additional image displays the effects when the given value contains less than three values or if you altered the value to only contain two or less values.