2

I am using GCC. I have a string containing the hex value of a UTF-8 char like this:

char[] str = "4e86"

(such kind of strings are read out from an xml-file). I would like this to convert this to a wchar containing the character \u4e86.

I know I can directly define

wchar_t wc = L'\u4e86';

but I would like a function like this

wchar_t wc = convert(str)

How?

1 Answer 1

4

Try this:

char[] str = "4e86";
wchar_t wc = strtol(str, NULL, 16);

(ref: https://stackoverflow.com/a/10156436/999400)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.