String comparison in Crystal Reports and Excel
Posted on 2014-04-02
Can anyone please explain to me how Crystal Reports and Excel decide which is the greater of two text strings?
I would have thought that it would work like this:
a. compare character 1 of the two strings
b. If character 1 of both strings is identical, then compare character 2 of each string.
c. Continue until a non-identical pair of characters is found.
d. the string with the higher character is greater than the other one.
Take an example: Compare String 1 "ANTEATERS" to String 2 "AARDVARK"
Compare character 1 of the two strings
Both characters are identical ("A"), so compare character 2 of the two strings
N is greater than A so "ANTEATERS" is greater than "AARDVARK".
In practice it isn't working that way, and I cannot figure out the logic these programs are using.
When I compare "C-" to "CA", Crystal Reports and Excel both tell me that "C-" is less than "CA".
But when I compare "C-W" to "CAB", Crystal Reports and Excel both tell me that "C-W" is greater than "CAB".
Can anyone explain to me how the programs are reaching this conclusion? Any help would be much appreciated!