简体   繁体   中英

How to convert a string containting the hex value of a UTF-8 to a wchar in C?

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 \了.

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?

Try this:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM