Python-like slicing and handling UTF-8 strings as a bonus
FG
home at fgda.pl
Sat Dec 29 15:02:36 PST 2012
On 2012-12-29 23:55, FG wrote:
> Probably because I like concise code. I always prefer:
> if (A) print(getMessage().getSlice(0..100));
>
> to writing something like this:
> auto message = getMessage();
> if (A) print(message.length > 100 ? message[0..100] : message);
>
Actually, when I look at this, it can be a one-liner after all. :)
if (A) print(getMessage()[0..($>100?100:$)]);
Didn't expect this to work.
More information about the Digitalmars-d
mailing list