[Gambas-user] Natural sorting in Gambas 3

Steven James Drinnan steven at ...2097...
Tue Jan 26 01:59:44 CET 2010


Wow that must be a first in a programming language, as most don't even
bother. It's something that I always had a bug bear about. But have
never had the time to implement this sort of sort on my programs. 

Great work, it this sort of functionality that has made Gambas great.

Steven Drinnan
On Mon, 2010-01-25 at 20:33 +0100, Olivier Cruilles wrote:
> Hi Benoit,
> 
> Thank you for this great new, I need exactly this kind of sort possibility, but in Gambas 2.xx... 
> 
> I'll wait for the stable Gambas 3.
> 
> Le 25 janv. 2010 à 20:16, Benoît Minisini a écrit :
> 
> > Hi,
> > 
> > I have implemented string natural comparison and sorting in the last Gambas 3 
> > revision.
> > 
> > With that, you can, for example, sort a file name array returned by Dir() that 
> > way:
> > 
> > 	Photo1.jpg Photo1a.jpg Photo1b.jpg Photo2.jpg ... Photo9.jpg Photo10.jpg
> > 	Photo11.jpg
> > 
> > Instead of:
> > 
> > 	Photo1.jpg Photo10.jpg Photo 11.jpg Photo1a.jpg Photo1b.jpg Photo2.jpg ... 
> > 	Photo9.jpg
> > 
> > For that, use the gb.Natural constant as sort flag.
> > 
> > Moreover, if you have non-ASCII letters, you can add gb.Language to the flag, 
> > and non-ASCII characters will be correctly sorted too. You will get:
> > 
> > 	Baba.jpg Bébé1.jpg Bébé8.jpg Bébé20.jpg Bibi.jpg Bobo.jpg
> > 
> > instead of:
> > 
> > 	Baba.jpg Bibi.jpg Bobo.jpg Bébé1.jpg Bébé20.jpg Bébé8.jpg 
> > 
> > How does it work?
> > 
> > The string is splitted between parts having digits only (0-9), and parts 
> > having no digits.
> > 
> > Parts having no digits are sorted as normal strings. 
> > 
> > Parts having digits are sorted according to their numerical values, unless it 
> > starts with a zero.
> > 
> > Enjoy it!
> > 
> > -- 
> > Benoît Minisini
> > 
> > ------------------------------------------------------------------------------
> > The Planet: dedicated and managed hosting, cloud storage, colocation
> > Stay online with enterprise data centers and the best network in the business
> > Choose flexible plans and management services without long-term contracts
> > Personal 24x7 support from experience hosting pros just a phone call away.
> > http://p.sf.net/sfu/theplanet-com
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> 
> Olivier Cruilles
> Mail: linuxos at ...1896...
> 
> 
> 
> ------------------------------------------------------------------------------
> The Planet: dedicated and managed hosting, cloud storage, colocation
> Stay online with enterprise data centers and the best network in the business
> Choose flexible plans and management services without long-term contracts
> Personal 24x7 support from experience hosting pros just a phone call away.
> http://p.sf.net/sfu/theplanet-com
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
> 





More information about the User mailing list