Louis van Alphen wrote:
I have a Palm application where I use StrCompare to sort strings for
the purpose of ordering them in a PDB. I also use the StrCompare in
a binary search routine.
I have a conduit developed with Delphi in which I sort records prior
to inserting them into the PDB (so that they are already ordered after
Sync).
However, I have established that the sort order on the Palm platform
is different from sort order in Delphi. This means that my binary
search falls to pieces. This is due to the string comparison functions
not working the same.
StrCompare() uses TxtCompare() to do its work. TxtCompare() treats
lowercase and uppercase letters as the same for the purposes of
ordering (so that "Taj Mahal" comes between "stick" and "umbrella")
but distinct for the purposes of equivalence (so that "Apple" isn't
equivalent to "apple"). I think TxtCompare() also deals with
multibyte characters in locales that use them. It may also treat
accented characters as equivalent to unaccented ones for the
purposes of ordering.
If you aren't picky about what order the items are actually in as
long as you can find them, the simplest thing would probably be
to use StrCompareAscii() instead. It just compares the numeric
value of the character bytes, so it's nice and simple, but it will
put all uppercase stuff before lowercase and so on.
If you do need the stuff to be in a more presentable order, it's
probably easier to just write your own function, which is what I
did in a similar case. I have a lookup table that converts
everything into a canonical form (mapping "e", "E", "e" with an
accent, etc. all to lowercase "e"). I then compare using the
canonicalized versions of everything once, and if those two are
equal, I compare again with StrCompareAscii().
- Logan
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/