String Comparisons

Like numeric expressions, string expressions can be compared in the diamond symbols for select and loop structures.  The same comparators are used:

 

=, !=, /=, <, <=, >, <=

 

For two strings to be equal (and for the = comparator to return a value of yes or true), they must be identical in length, and the ASCII codes for corresponding characters must match.  So, "abc" is NOT equal to "abc " (note the space at the end) or "Abc" (upper-case A is not the same as lower-case a).

 

One string is less than another if it comes earlier in "alphabetical order", which for us is ASCII order.   For example, "abc" is less than "abd".  However, because upper-case letters have lower ASCII values than their lower-case siblings, "Abc" is less than "abc".  Finally, the ordering rules for strings tell us that "abc" is less than "abcdef".

 

Just to remind you of the general ordering of characters in ASCII, below is the relative ASCII ordering for different classes of characters:

 

Control Characters  <  Punctuation Characters  <  Digit Characters  <  Upper-Case Letters  <  Lower-Case Letters.

 

Consult your ASCII chart for further details.