STRING_COMPARE [MATCHCASE] string1 string2 resultVariable

The STRING_COMPARE command compares string1 to string2 typographically and puts a number representing that comparison into resultVariable:

  • If string1 is less than string2 (I.e., string1 would come prior to string2 if they were to be sorted in ascending order) then resultVariable will contain a negative number.

  • If string1 is greater than string2 (I.e., string1 would come after string2 if they were to be sorted in ascending order), then resultVariable will contain a positive number.

  • If both strings are identical, then resultVariable will contain zero.

By default, the comparison is made ignoring typographical case. If you want to match case, add the matchCase keyword.





See also: STRING, STRING_REPLACE


In this example program, you enter two strings and the program tells you the result of the comparison. Enter "quit" without the quotes to quit the program.

quitVal = 1
UNTIL quitVal = 0
   INPUT STRING "Please enter aStr (or \"quit\" to quit): " aStr
   STRING_COMPARE aStr "quit" quitVal
   IF quitVal <> 0
      INPUT STRING bStr
      STRING_COMPARE aStr bStr result
      IF result < 0
      'Commands to do if aStr < bStr:
         STRING aStr " is less than " bStr resultString
      ELSEIF result > 0
      'Commands to do if aStr > bStr:
         STRING aStr " is greater than " bStr resultString
      ELSE
      'Commands to do if aStr = bStr:
         STRING aStr " is equal to " bStr resultString
      END
      PRINT resultString
   END
END
EXIT "Quitting ..."