Rexx Programming/How to Rexx/string comparison

String comparisons are made based upon lexical string order

edit

String operators make comparisons based upon the lexical string order. Strings listed first in lexical order have a lower comparative value than strings listed later.

Supported operators

edit

The following example shows a string comparison being made using the comparative operators:

animal = 'dog'
if animal > 'cat' then
  say animal "is lexically higher than cat"

The following comparative operators are supported:

edit
= 	Equal To
\= 	Not Equal To
< 	Less Than
> 	Greater Than
<= 	Less Than or Equal To
>= 	Greater Than or Equal To
\< 	Not Less Than
\> 	Not Greater Than
<> 	Not Equal To
>< 	Not Equal To

Conventional string comparative operators ignore leading and trailing whitespace

edit

The conventional string comparison operators ignore leading and trailing whitespace when the comparison is made:

'  ' =        /* 1 true,  string comparison  (stripped whitespace matches null value)  */
'ABC' = ' ABC ' /* 1 true,  string comparison  (leading and trailing whitespace ignored) */

Strict Comparison

edit

The strict comparative operators do not ignore leading and trailing whitespace, which must also match when a strict comparison is made:

'  ' ==        /* 0 false,  strict comparison  (the spaces will not match the null value)  */
'ABC' == ' ABC ' /* 0 false,  strict comparison  (leading and trailing whitespace causes mismatch) *# /