sort strings by interpreting them as integrals

Jonathan M Davis jmdavisProg at gmx.com
Sun Jul 29 19:44:10 PDT 2012


On Monday, July 30, 2012 04:39:26 bearophile wrote:
> Jonathan M Davis:
> > void main()
> > {
> > 
> >     string[] x = ["_100", "_10", "_20"];
> >     sort!"a.length < b.length ? true : a < b"(x);
> >     writeln(x);
> > 
> > }
> > 
> > I get an AssertError about it failing to sort, but the result
> > is correct.
> 
> Take a look at my solution (another thread, it seems), why are
> you comparing the length of the strings?

Otherwise, wouldn't _100 come before _20?

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list