String comparson happens like this: the computer skips those characters at the front of both strings where they are equal, and it stops either at the end of the shortest of the two strings (if they have the same length, then they're equal, otherwise the shortest string comes first) or at the first character where they are different, and there, it's the "smallest" character that determines which string comes first.
The most easy way to compare characters in the computer is to compare by their character code: each character has a number assigned to it. It is stored that way: as numbers, which may be a single byte, or several bytes together representing a number.
The most common character set in modern computer systems is ASCII, or, something based on ASCII, like ISO-Latin-1, or, by extension, on Unicode.
According to ASCII, letters are ordered in order of the alphabet, which is handy, but upper case letters come first, and there are a few other characters in between them.
So the sort order of ordinary strings may not exactly e as you expect. Well, at least a space has the lowest character code of all printable characters, which is also nice. But a "Z" comes before "a" and that is not so nice; worse still, accented characters come very much farther down.
The ideal sorting order (or "collation order", as it is also known) for humans isn't uniform, actually depends on the language used.
That's why they came up with locales, so you can sort strings according to your own language.
(Actually it's not even that simple, as a locale may count several characters as one, or vice versa. Have you lost your head, yet? :) That's normal, I assure you.)
In reply to Re: comparision operators
by bart
in thread comparision operators
by rob171171
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |