Skip to main content

String Relational Operators

String Relational Operators

String relational operators use the string interpretation of the operands to produce a Boolean result. You can precede any of the string relational operators with the NOT logical operator (') to obtain the negation of the logical result. ObjectScript provides the following string relational operators:

Equals (=)

The Equals operator tests two operands for string equality. When you apply Equals to two strings, ObjectScript returns a result of TRUE (1) if the two operands are identical strings with identical character sequences and no intervening characters, including spaces; otherwise it returns a result of FALSE (0). For example:

 WRITE "SEVEN"="SEVEN"    // 1
 WRITE "SEVEN"="seven"    // 0
 WRITE "SEVEN"=" SEVEN "  // 0

For details, see the Equals (=) reference page. Also see the Not Equals ('=) reference page.

Contains ([)

Contains tests whether the sequence of characters in the right operand is a substring of the left operand. If the left operand contains the character string represented by the right operand, the result is TRUE (1). If the left operand does not contain the character string represented by the right operand, the result is FALSE (0). If the right operand is the null string, the result is always TRUE.

For example:

 SET L="Steam Locomotive"
 SET S="Steam"
 WRITE L[S  /// 1

For details, see the Contains ([) reference page. Also see the Does Not Contain ('[) reference page.

Follows (])

Follows tests whether the characters in the left operand come after the characters in the right operand in ASCII collating sequence. Follows tests both strings starting with the left most character in each.

For example:

 WRITE "LAMPOON"]"LAMP"  // 1

For details, see the Follows (]) reference page. Also see the Not Follows (']) reference page.

Sorts After (]])

Sorts After tests whether the left operand sorts after the right operand in numeric subscript collation sequence. In numeric collation sequence, the null string collates first, followed by canonical numbers in numeric order with negative numbers first, zero next, and positive numbers, followed lastly by nonnumeric values.

For example:

 WRITE 122]]2  // 1

For details, see the Sorts After (]]) reference page. Also see the Not Sorts After (']]) reference page.

FeedbackOpens in a new tab