Substring
Value resolver – Abstract
Purpose: Returns a continuous section (substring) of the string passed as input value.
The Substring value resolver returns a continuous section (Substring) of the string passed as input value.
The Begin index and Max. length parameters define the position and the (maximum) length of the returned section.
If no value ($null) is present as input value, no value ($null) is returned.
For input values that are not strings, their string mapping is processed.
Configuration
Parameter |
Value range |
Meaning |
Begin index |
>=0 |
Index counts from left to right; 0 points to the first character of the input value |
<0 |
Index counts from right to left; -1 points to the last character of the input value |
|
Max. Length |
0 |
'All' (any number of) characters starting from the line item defined by the Begin index |
>0 |
Maximum number of characters from the item defined by Begin index |
|
<0 |
Error (Process Exception: String index out of range) |
Both parameters can be set by direct input (as a positive or negative integer) or via a value resolver at runtime.
In the example on the right, the value -10 was entered directly for the Begin index. The returned section therefore starts with the tenth character from the end of the string passed as the input value. For the Max. length parameter, a Variable value resolver is used so that at runtime the value of the maxCharacters variable is used to limit the length of the section ►NOTE◄ Starting from the direct input provided by default, the definition of a value resolver must be initiated by clicking on the small gray arrow at the bottom left of the input value (see Begin index in the screenshot). If 'no value' (from the context menu) is selected instead of a value resolver, the direct input appears again the next time the Substring value resolver is expanded. |
|
Examples
Examples of parameterization
The following table illustrates the effect of the substring value resolver with different parameters using the example of the string SCMU3216083 BLU/WHT 40ft as input value (11-digit BIC code of a container followed by a space and then description text):
Begin index |
Max. Length |
Result |
Comment |
0 (or: no value) |
0 (or: no value) |
SCMU3216083 BLU/WHT 40ft |
All characters |
0 (or: no value) |
3 |
SCM |
Owner (first three characters of the container number) |
12 |
0 (or: no value) |
BLU/WHT 40ft |
Description (any number of characters from 13th character) |
10 |
1 |
3 |
Check digit (at the end of the container number, i.e. 11th character) |
-4 |
0 (or: no value) |
40ft |
Here: Container type (convention: 'last 4 characters') |
-4 |
2 |
40 |
Here: Digits for length of the container in feet (according to convention) |
-80 |
0 (or: no value) |
SCMU3216083 BLU/WHT 40ft |
The last 80 characters → 'all' if less than 81 characters |
0 (or: no value) |
80 |
SCMU3216083 BLU/WHT 40ft |
The first 80 characters → 'all' if less than 81 characters |
More complex configuration example
The readability of a string that combines the BIC code of a container with a description text of undefined length, as in the example above, is improved by inserting spaces between the segments within the container number.
Runtime example:
►NOTE◄ The following configuration demonstrates the use of the Substring value resolver in the context of a loop with dynamic assignments for the parameters. The desired 'segmentation' of the string can also be achieved using the Replace text value resolver via a regular expression.
Configuration:
To make it as easy as possible to adjust the 'segmentation' of the string as needed, the following configuration defines the desired length of the segments in question using a static string that can be interpreted as an array of integers in the JSON notation: [3,1,6,1,0] The value 0 at the last position means that all characters after the 11-digit (3+1+6+1) container number should be output. The JSON to object value resolver generates a list of integers from the static text, which can be processed in the header of a For each loop in the Resolver for entities parameter. In the loop header, the Save String in variable parameter specifies that the input value (the string to be structured) is stored in the input variable. This variable allows access to the string within one iteration of the loop. The screenshot on the right shows a Set value event action in the action block for iteration, which is used to successively build the structured string for output in the output variable. For this purpose, a Concat strings value resolver is used (right), which appends another Substring from the variable input to the previous content of the variable output with each iteration. The parameters in the Substring value resolver change for each iteration:
A space is inserted before each 'attachment' from the input variable (see position 2 in the Concat strings value resolver). To eliminate excess spaces, the Trim value resolver is concatenated in two places:
|
|
The cursor variable is used to define the starting point for each next iteration. This achieves another Set value event action, in which the number of characters taken over in the current iteration (see the segment variable in the Calculate value value resolver) is added to the previous cursor value. The 'value' of this sum defines the Begin index for the next section to be copied. It is assigned to the cursor variable. ►IMPORTANT◄ The output and cursor variables used in the loop should be initialized with the $null and 0 values, respectively, before the start of the loop, otherwise " presets" of these variables can falsify the result. |
|