On Sunday, 25 August 2013 at 19:51:50 UTC, qznc wrote:
Thanks, somewhat unintuitive.

Yes, but un-intuitive... to the un-initiated. By default, it's also safer. A string *is* conceptually, a sequence of unicode codepoints. The fact that it is made of UTF-8 codepoints is really just low level implementation detail.

Thanks to this behavior, things like:
string s = "日本語"
//search for '本';
for ( ; s.front != '本' ; s.popFront())
{}

Well, they *just work* (TM).

Now... If you *know* what you are doing, then by all means, iterate on the UTF8 code units. But be warned, you must really know what you are doing.

Back to your original subject, you can use:
ElementEncodingType!S

ElementEncodingType works just like ElementType, but for strings, *really* takes the array's element's type. This is usually *not* the default you want.

Also related, foreach naturally iterates on codeunits by default (for some weird reason). I recommend to try to iterate on dchars.

Reply via email to