Substring

Value resolver – Abstract

Purpose: Returns a continuous section (substring) of the string passed as input value.

images/download/attachments/106957538/image2022-6-27_12-42-47-version-1-modificationdate-1656326567202-api-v2.png

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
(default: 0)

>=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
(default: 0)

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.

images/download/attachments/106957538/image2022-6-27_12-44-7-version-1-modificationdate-1656326647078-api-v2.png

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:

images/download/attachments/106957538/image2022-6-27_11-57-17-version-1-modificationdate-1656323837618-api-v2.png

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:

  • The Begin index is read from a cursor variable, which is recalculated in the following step per iteration.

  • As Max. length is the integer from the array defined in the loop header that is valid as the reference object for the respective iteration and that is returned by the Object property value resolver without specifying a field.

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:

  • When concatenated with the Substring value resolver, the 'inner' Trim value resolver prevents a double space from appearing in the output before the description text, which is already separated by a space in the input.

  • The 'outer' Trim value resolver below the Concat strings is essentially used to eliminate the leading space before the first segment, which occurs because the output variable in the first iteration does not yet contain a character.

images/download/attachments/106957538/image2022-6-27_12-46-59-version-1-modificationdate-1656326819696-api-v2.png

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.

images/download/attachments/106957538/image2022-6-27_12-48-0-version-1-modificationdate-1656326880862-api-v2.png