|
Comparing String Expressions
GPP compares two string expressions in the following way:
-
Strings are compared one character at a time, in a case-sensitive way (so 'A' is not equal to 'a').
-
As soon as one different character is found, comparison stops. GPP determines which string has the "smaller" character based on the ASCII table, and that string is considered "smaller" than the other.
-
If no different character is found, and one string ends before the other - that string is considered to be "smaller" than the other.
-
If all characters are the same, and the strings end together, they are considered equal.
It is possible to use all the comparison operators for strings, such as '==', '<', etc. They work in the intuitive way under the definition of string comparison listed above.
Example
"abcd" is smaller than "abx" (since c < x)
"abcd" is larger than "abc" (since the first string is longer)
"abc" is larger than "ABC" (since in ASCII 'a' comes after 'A')
Note: If case-insensitive comparison is wanted, the STR_LOWER (or STR_UPPER) function can be used to convert both expressions to lowercase (or uppercase) before using them in the comparison expression.
STR_LOWER("abc") is equal to STR_LOWER("ABC")
GPP Compatibility Notes:
In the old GPP, string comparison was done in a non-standard way. It ignored any trailing spaces, so that "abc " and "abc" were found to be equal. This behavior was not kept in GPP2, which uses standard string comparison.
In the old GPP, it was only possible to compare a string variable with a string constant. Also, it was only possible to check if the string is equal or not equal to the constant. In GPP2, any two string expressions can be compared, using any of the comparison operators.
|