[Gambas-user] Sorting the human way

Alain Baudrez a.baudrez at ...626...
Wed Oct 23 09:20:06 CEST 2013


Hoi,

I've never been happy with the standard sorting algorithm when dealing with
lists of names. The human eye expects the names to be listed
alphabetically, overlooking spaces, hyphens, accented characters, ...

Assume the following names:
     - Benoizy
     - Benoît
     - Benï Lewis
     - Benoix
     - Ben Underwood

Sorting them using the default sort method results in the following list:
     - Ben Underwood
     - Benoix
     - Benoizy
     - Benoît
     - Benï Lewis

       Ben Underwood comes first due to the space having an UTF-8 value of
 
       Benoît comes last in the Benoi series of names due to the UTF-8
value of î which is ï
       Benï Lewis comes last of the list as ï has a UTF-8 value of î

Using the function Alfabet to sort the list, the end result using the
original strings appears in the form :
     - Benï Lewis
     - Benoît
     - Benoix
     - Benoizy
     - Ben Underwood

       which is the normal order a human expect to see when you ignore
spaces, accents, umlauts, ...

In annex I sent a function I have written that strips a string from all the
non-letter characters and returns a simple pure ascii string with all
characters in the range "a"-"z". Also included a small snapshot of an
actual list sorted by alphabet in one of my programs. As you notice, the
names are truly listed 'by Alphabet'

Feel free to use the function or maybe the concept could be incorporated in
a future build of Gambas

Alain J. Baudrez
-------------- next part --------------
A non-text attachment was scrubbed...
Name: modUDF.module
Type: application/octet-stream
Size: 6214 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20131023/7f4e1e10/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alphabet.png
Type: image/png
Size: 33764 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20131023/7f4e1e10/attachment.png>


More information about the User mailing list