lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Andreas,
"a" is greater than "A" because of the ASCII definitions!
"a" is character 97 decimal, while "A" is decimal 65.

To compare in a case-insensitive way, just convert both strings to uppercase (or lowercase) with string.upper.
(Of course there are other ways to do this :-)
Matt

Andreas Falkenhahn wrote:
Hi,

I noticed that the following expression is actually FALSE in lua:

"Big" > "ants"

This seems to happen because of the difference in case because
the following expression is TRUE:

"Big" > "Ants"

Is there any specific reason why lua does string comparison in
this way? I.e. giving lower case characters a higher priority than
all of the upper case characters? I.e. the following is TRUE:

"a" > "Z"

It's a little bit confusing... especially when using the sort() function
of lua's table library. When sorting a string table using this function,
the sorted table will have two different entities, upper and lower case,
e.g. doing

t = {"Dave", "dave", "mary", "Mary", "Adam", "adam"}
table.sort(t)

will lead to:

Adam
Dave
Mary
adam
dave
mary

But I'd like to have it like this:

Adam
adam
Dave
dave
Mary
mary

Is there any way to change this behaviour or do I have to use a
custom sort callback with table.sort() that does a case insensitive
string comparison? But that would probably be very slow...
Tks for any ideas,

Andreas
--
"Remember: It's nice to be important but it's more important to be nice!"