String Relational Operators

M relational operators always generate a result of TRUE (1) or FALSE (0). All string relational operators force M to evaluate the expressions to which they apply as strings. The string relational operators are:

= binary operator causes M to produce a TRUE if the expressions are equal.

[ binary operator causes M to produce a TRUE if the first expression contains the ordered sequence of characters in the second expression.

] binary operator causes M to produce a TRUE if the first expression lexically follows the second expression in the character encoding sequence, which by default is ASCII.

]] binary operator causes M to produce a TRUE if the first expression lexically sorts after the second expression in the subscript collation sequence.

Note that all non-empty strings lexically follow the empty string, and every string contains the empty string.

Other string relations are formed using the logical NOT operator apostrophe (') as follows:

'[ does not contain.

'] does not follow, that is, lexically less than or equal to.

']] does not sort after, that is, lexically less than or equal to in the subscript collation sequence.

'= not equal, numeric or string operation.

Example:

        GTM>WRITE "A"="B"
        0
        GTM>WRITE "C"="C"
        1
        GTM>WRITE "A"["B"
        0
        GTM>WRITE "ABC"["C"
        1
        GTM>WRITE "A"]"B"
        0
        GTM>WRITE "B"]"A"
        1
        GTM>WRITE "A"]]"B"
        0
        GTM>WRITE "B"]]"A"
        1
        

These examples demonstrate the string relational operators using string literals.

Example:

        GTM>WRITE 2]10
        1
        GTM>WRITE 2]]10
        0
        GTM>WRITE 0]"$"
        1
        GTM>WRITE 0]]"$"
        0
        

These examples illustrate that when using the primary ASCII character set, the main difference in the "follows" (]) operator and the "sorts-after" (]]) operator is the way they treat numbers.

Example:

        GTM>WRITE 1=1
        1
        GTM>WRITE 1=2
        0
        GTM>WRITE 1="1"
        1
        GTM>WRITE 1=01
        1
        GTM>WRITE 1="01"
        0
        GTM>WRITE 1=+"01"
        1
        GTM>
        

These examples illustrate the dual nature of the equal sign operator. If both expressions are string or numeric, the results are straight forward. However, when the expressions are mixed, the native string data type prevails.

Example:

        GTM>WRITE "a"'="A"
        1
        GTM>WRITE "FRED"'["RED"
        0
        GTM>WRITE "ABC"']""
        0
        

These examples demonstrate combinations of the string relational operators with the NOT operator.