how to get the \uxxxx unicode code from a char
jicman via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Oct 14 13:18:47 PDT 2014
On Tuesday, 14 October 2014 at 19:56:29 UTC, ketmar via
Digitalmars-d-learn wrote:
> On Tue, 14 Oct 2014 19:46:57 +0000
> jicman via Digitalmars-d-learn
> <digitalmars-d-learn at puremagic.com>
> wrote:
>
>> char[] s = "ABCabc";
>> foreach (char c; s)
>> {
>> // how do I convert c to something an Unicode code? ie.
>> \u9999.
>>
>> }
> string res;
> foreach (dchar ch; s) res ~= "\\u%04X".format(ch);
> // here we have the result in res
>
> note "dchar" instead of "char". with "dchar" foreach() does
> utf-8
> decoding (as 's' is in utf-8).
Thanks. This is a missing function in std.uni or std.string.
josé
More information about the Digitalmars-d-learn
mailing list