String Operators

String operators provide functionality for string manipulation and comparison in DataLogic-rs rules.

cat
substr
starts_with
ends_with
upper
lower
trim

cat

The cat operator concatenates multiple strings together.

Syntax

{ "cat": [string1, string2, ...] }

Parameters

Parameter Description
strings An array of strings or expressions that evaluate to strings

Example: Simple String Concatenation

Rule:

Data:

Result:

Example: Concatenation with Variables

Rule:

Data:

Result:

substr

The substr operator extracts a substring from a string, starting at a specified position and optionally extracting a specified number of characters.

Syntax

{ "substr": [string, start_index, length] }

Parameters

Parameter Description
string The input string to extract from
start_index The start position (0-indexed)
length (optional) The number of characters to extract (if omitted, extracts until end of string)

Example: Extract Substring

Rule:

Data:

Result:

Example: Extract to End of String

Rule:

Data:

Result:

starts_with

The starts_with operator checks if a string starts with a specified prefix.

Syntax

{ "starts_with": [string, prefix] }

Parameters

Parameter Description
string The string to check
prefix The prefix to look for at the start of the string

Example: Check if string starts with prefix

Rule:

Data:

Result:

Example: Case sensitivity

Rule:

Data:

Result:

ends_with

The ends_with operator checks if a string ends with a specified suffix.

Syntax

{ "ends_with": [string, suffix] }

Parameters

Parameter Description
string The string to check
suffix The suffix to look for at the end of the string

Example: Check if string ends with suffix

Rule:

Data:

Result:

Example: Using with conditional

Rule:

Data:

Result:

upper

The upper operator converts a string to uppercase.

Syntax

{ "upper": string }

Parameters

Parameter Description
string The string to convert to uppercase

Example: Convert string to uppercase

Rule:

Data:

Result:

Example: Combining with other operators

Rule:

Data:

Result:

lower

The lower operator converts a string to lowercase.

Syntax

{ "lower": string }

Parameters

Parameter Description
string The string to convert to lowercase

Example: Convert string to lowercase

Rule:

Data:

Result:

Example: Case-insensitive comparison

Rule:

Data:

Result:

trim

The trim operator removes whitespace characters from the beginning and end of a string.

Syntax

{ "trim": string }

Parameters

Parameter Description
string The string to trim

Example: Remove leading and trailing whitespace

Rule:

Data:

Result:

Example: Combine with other operators

Rule:

Data:

Result: