简体   繁体   English

c# - 如何将表示unicode字符的数字(大于0xFFFF)转换为其等效字符串#

[英]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:例如中日韩统一表意文字扩展A中的一个字符'𠀀',它的unicode值为0x20000,因为c#中的char不能表示这样的字符,所以我想知道我是否可以将其转换为字符串,我的问题是:

If I give you a number like 0x20000, how to convert it and let me get it's equivlent string like "𠀀"如果我给你一个像 0x20000 这样的数字,如何转换它并让我得到它的等效字符串,比如“𠀀”

You can use char.ConvertFromUtf32 for that:您可以使用char.ConvertFromUtf32

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: string本身是一个 UTF-16 代码单元序列,在本例中为 U+D840 和 U+DC00,您可以通过打印出各个char值来查看它们:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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