小编har*_*gle的帖子

将Unicode代理项对转换为文字字符串

我试图从一个字符串到另一个字符串读取高Unicode字符.为简洁起见,我将简化我的代码,如下所示:

public static void UnicodeTest()
{
    var highUnicodeChar = ""; //Not the standard A

    var result1 = highUnicodeChar; //this works
    var result2 = highUnicodeChar[0].ToString(); // returns \ud835
}
Run Code Online (Sandbox Code Playgroud)

当我直接分配highUnicodeCharresult1,它保留其文字值. When I try to access it by index, it returns \ud835.据我了解,这是一对代表UTF-32字符的替代UTF-16字符.我很确定这个问题与尝试隐式转换char为a有关string.

最后,我想得到与之result2相同的价值result1.我怎样才能做到这一点?

.net c# unicode unicode-escapes

16
推荐指数
2
解决办法
923
查看次数

标签 统计

.net ×1

c# ×1

unicode ×1

unicode-escapes ×1