简体   繁体   中英

How to convert unicode codepoint like U+1F4DB to char?

I have in string a code point like U+1F4DB and I would like to convert it to a unicode char (📛). How to do ?

You can't convert that to a single char . That code point is outside of the range that can be represented in UTF-16 as a single 16 bit element. Instead it is represented by a surrogate pair, two char elements. In Delphi it would be expressed as the string

#$D83D#$DCDB

as can be discerned from this page: http://www.fileformat.info/info/unicode/char/1f4db/index.htm

In practise I think it would be simpler to paste the character into your source code, inside a string literal, and let the source code be stored encoded as UTF-8. The IDE will prompt to do so automatically. That is represent it as

'📛'

In comments you make it clear that you wish to parse arbitrary text of the form U+xxxx. Extract the numeric value and convert it to an integer. Then pass it through TCharHelper.ConvertFromUtf32 .

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