Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert a number (larger than 0xFFFF) that represents a unicode character to it's equivlent string in c#

help!

For example, a character ‘𠀀’ in CJK Unified Ideographs Extension A, It’s unicode value is 0x20000, as char in c# can’t represent such character, so I wonder if I could convert it to string, my question is:

If I give you a number like 0x20000, how to convert it and let me get it’s equivlent string like "𠀀"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use char.ConvertFromUtf32 for that:

int utf32 = 0x20000;
string text = char.ConvertFromUtf32(utf32);

string itself is a sequence of UTF-16 code units, in this case U+D840 and U+DC00, which you can see by printing out the individual char values:

int utf32 = 0x20000;
string text = char.ConvertFromUtf32(utf32);
Console.WriteLine(((int) text[0]).ToString("x4")); // d840
Console.WriteLine(((int) text[1]).ToString("x4")); // dc00
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading