我试图从一个字符串到另一个字符串读取高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)
当我直接分配highUnicodeChar时result1,它保留其文字值. When I try to access it by index, it returns \ud835.据我了解,这是一对代表UTF-32字符的替代UTF-16字符.我很确定这个问题与尝试隐式转换char为a有关string.
最后,我想得到与之result2相同的价值result1.我怎样才能做到这一点?