sort strings by interpreting them as integrals

bearophile bearophileHUGS at lycos.com
Sun Jul 29 19:39:26 PDT 2012


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?

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list