how to get the \uxxxx unicode code from a char

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Oct 14 12:56:18 PDT 2014


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).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141014/a8dbe4d8/attachment.sig>


More information about the Digitalmars-d-learn mailing list