How to loop through characters of a string in D language?

Stanislav Blinov stanislav.blinov at gmail.com
Wed Dec 8 22:35:35 UTC 2021


On Wednesday, 8 December 2021 at 22:18:23 UTC, forkit wrote:

> It's also worth noting the differences in compiler output, as 
> well as the time taken to compile, these two approaches:
>
> (1)
> string str = "abc;def;ab".filter!(c => c != ';').to!string;
>
> (2)
> string str = "abc;def;ab".replace(";", "");
>
> see: https://d.godbolt.org/z/3dWYsEGsr

You're passing a literal. Try passing a runtime value (e.g. a 
command line argument). Also, -O2 -release :) Uless, of course, 
your goal is to look at debug code.


More information about the Digitalmars-d-learn mailing list