Why the hell doesn't foreach decode strings

Daniel Gibson metalcaedes at gmail.com
Sat Oct 22 04:01:19 PDT 2011


Am 22.10.2011 12:55, schrieb Alvaro:
> El 20/10/2011 21:37, Martin Nowak escribió:
>> It just took me over one hour to find out the unthinkable.
>> foreach(c; str) will deduce c to immutable(char) and doesn't care about
>> unicode.
>> Now there is so many unicode transcoding happening in the language that
>> it starts to get annoying,
>> but the most basic string iteration doesn't support it by default?
>
> Maybe I didn't fully get your point, but, you do know that you can do
> the following, right?
>
> string str = "Ñandú";
> foreach(dchar c; str)
> ...

One visible Unicode character can consists of several dchars.
(This is called "Grapheme")

Cheers,
- Daniel


More information about the Digitalmars-d mailing list