问题描述
亲爱的专家
我正试图了解.NET字符串和Unicode的所有细节。从我读到的,.NET字符串是UTF16编码。
基于这个知识/假设我试图看看BMP的代码点将如何由.net字符串处理并在我的第一个实验中失败。
我的代码
Dear experts
I’m trying to understand .NET strings and Unicode in all its details. From what I read, .NET strings are UTF16 coded.
Based on this "knowledge"/"assumption" I tried to see how Code Points out of BMP will be handled by .net strings and failed on my very first experiment.
My code
int music = 0x1D161; //U+1D161 = MUSICAL SYMBOL SIXTEENTH NOTE
string s1;
s1= Char.ConvertFromUtf32(music);
textBox1.Text = s1;
使用上面的代码我预计
a。)在文本框中看到音乐符号,但我只看到一个正方形
b。)s1.Length返回一个(即使代码点需要两个代码单元 - 代理对 - ?),但长度返回2
有没有人可以解释我错在哪里?
非常感谢您提前。
Bruno
With the above code I expected
a.)to see the musical symbol in the text box , but I see only a square
b.)s1.Length returns one (even the code point needs two code units – surrogate pair- ? ), but Length returns 2
Does anybody can explain me where I’m wrong?
Thank you very much in advance.
Bruno
推荐答案
这篇关于Unicode,UTF16,.NET - 字符串,BMP中的CodePoint(基本多语言平面)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!