what's the correct way to handle unicode? - trying to print out graphemes here.
aliak
something at something.com
Tue Jul 3 13:36:56 UTC 2018
On Tuesday, 3 July 2018 at 13:32:52 UTC, aliak wrote:
> Hi, trying to figure out how to loop through a string of
> characters and then spit them back out.
>
> Eg:
>
> foreach (c; "👩👩👦👦🏳️🌈") {
> writeln(c);
> }
>
> So basically the above just doesn't work. Prints gibberish.
>
> So I figured, std.uni.byGrapheme would help, since that's what
> they are, but I can't get it to print them back out? Is there a
> way?
>
> foreach (c; "👩👩👦👦🏳️🌈".byGrapheme) {
> writeln(c.<????>);
> }
>
> And then if I type the loop variable as dchar, then it seems
> that the family empji is printed out as 4 faces - so the code
> points I guess - and the rainbow flag is other stuff (also its
> code points I assume)
>
> Is there a type that I can use to store graphemes and then
> output them as a grapheme as well? Or do I have to use like lib
> ICU maybe or something similar?
>
> Cheers,
> - Ali
Hehe I guess the forum really is using D :p
The two graphemes I'm talking about (which seem to not be
rendered correctly above) are:
family emoji: https://emojipedia.org/family-woman-woman-boy-boy/
rainbow flag: https://emojipedia.org/rainbow-flag/
More information about the Digitalmars-d-learn
mailing list