Best approach to handle accented letters

Chris via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 28 06:17:20 PDT 2016


On Friday, 28 October 2016 at 12:52:04 UTC, Marc Schütz wrote:
> On Friday, 28 October 2016 at 11:24:28 UTC, Alfred Newman wrote:
>> [...]
>
> import std.stdio;
> import std.algorithm;
> import std.uni;
> import std.conv;
>
> void main()
> {
>     auto str = "très élégant";
>     immutable accents = unicode.Diacritic;
>     auto removed = str
>         .normalize!NFD
>         .filter!(c => !accents[c])
>         .to!string;
>     writeln(removed);  // prints "tres elegant"
> }
>
> This first decomposes all characters into base and diacritic, 
> and then removes the latter.

Cool. That looks pretty neat and it should cover all cases.


More information about the Digitalmars-d-learn mailing list