Open main menu

Wikibooks β

Rexx Programming/How to Rexx/string comparison

< Rexx Programming‎ | How to Rexx


String comparisons are made based upon lexical string orderEdit

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 operatorsEdit

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 whitespaceEdit

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 ComparisonEdit

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) *# /