Why is the length of this string longer than the number of characters in it?

后端 未结 8 1057
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 19:26

This code:

string a = \"abc\";
string b = \"A         


        
8条回答
  •  悲哀的现实
    2020-11-29 20:08

    From the documentation of the String.Length property:

    The Length property returns the number of Char objects in this instance, not the number of Unicode characters. The reason is that a Unicode character might be represented by more than one Char. Use the System.Globalization.StringInfo class to work with each Unicode character instead of each Char.

提交回复
热议问题