Page 1 of 1

String Comparision

Posted: Sun Feb 07, 2010 8:42 am
by zulfi123786
Strings when they are compared with each other it happens at the character level i.e character by character comparision, when two strings are of unequal size then is the smaller string padded to make it equal with the longer string, if yes then with which character is it padded with?

Ex 'abcd'<'efghts'

In the above example does the single relational expressions becomes multiple expressions involving one character each time? "a<e", "b<f".....

If so then how is the final value decided, is it based on majority?
or is my understanding completely wrong please enlighten.....

Thanks

Posted: Sun Feb 07, 2010 12:25 pm
by ray.wurlod
You're almost there. Strings are compared character by character. If, when the end of the shorter string is encountered, no difference has been found, then the shorter string is "less than" the longer string.

No padding occurs.

Posted: Mon Feb 08, 2010 12:14 am
by zulfi123786
And what if the shorter string is greater than the longer string and the end of shorter string is encountered.

Posted: Mon Feb 08, 2010 12:39 am
by ray.wurlod
The comparison is character-by-character. Therefore as soon as one character in the shorter string is "greater than" the corresponding character in the other string, previous characters having matched exactly, then the shorter string is "greater than" the longer. For example, "WOLF" is greater than "AARDVARK", "Grease mop" is greater than "Grease ball". If you want to compare the lengths, then compare the lengths. Use the Len() function.