Python-like slicing and handling UTF-8 strings as a bonus

bearophile bearophileHUGS at lycos.com
Sat Dec 29 15:08:52 PST 2012


FG:

> to writing something like this:
>     auto message = getMessage();
>     if (A) print(message.length > 100 ? message[0..100] : 
> message);

In std.algorithm there is min(), that helps a little:

if (A)
     print(message[0 .. min($, 100)]);

Bye,
bearophile


More information about the Digitalmars-d mailing list