11.8: Character Comparisons
- Page ID
- 54311
The standard relational operators (“==”, “>”, “>=”, etc.) have some limitations when character data is used. Simple comparisons, such as,
"A" < "D" "ABC" == "ABC"
will work as expected. That is, both will evaluate to true.
However, when comparing, the following characters, each will evaluate to false.
"A" > "a" "20" < "100" "ABCD" <= "ABC"
This is a result of the relational operations referring to the assigned values (based on their location in the ASCII table located in Appendix A).
Comparisons between digits, “0” - “9”, will work relative to each other. Comparisons between upper- case letters, “A” - “Z”, will also work relative to each other. Comparisons between lower-case letters, “a” - “z”, will also work relative to each other. Since the lower case letters are after the upper case letters in the table an upper-case letter will be less than a lower-case letter. The digits are in the table before the letters (upper- and lower-case), so they will evaluate as less than letters. This must be taken into account when dealing with character comparisons.