What basis is used to determine lt ot gt here?
It's called Lexicographical order, and simply speaking it's comparing a pair of strings character by character, and stop as soon as a difference is encountered.
Or are you really asking about Locales?
| [reply] |
Many thanks Moritz, I just figured it out prior to your msg honest. Ok onto 'if'..
| [reply] |
- 'f' eq 'f'
- 'r' eq 'r'
- 'e' eq 'e'
- 'd' lt 'e'. ie. ord('d') == 100; ord( 'e' ) == 101; 100 < 101;
Therefore 'fred' lt 'free' is true.
But, I'm guessing you probably knew all that; so now you will ask your real question? :)
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |
Emm yes of course...,..., after some time looking at it that is.
Thank You BrowserUK
| [reply] |
You know how to look something up in a dictionary? Well, then...
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.)
| [reply] |