Inspired by my posting about supplementary characters in SQL Server 2012, I checked the capabilities of .Net to support supplementary characters:
string s143743 = "𣅿"; Console.WriteLine(s143743.Length.ToString()); Console.WriteLine(new StringInfo(s143743).LengthInTextElements.ToString()); string s131518 = "𠆾𠇀𠇃"; Console.WriteLine(s131518.Length.ToString()); Console.WriteLine(new StringInfo(s131518).LengthInTextElements.ToString());
The results are
“𣅿”
Length: 2
LengthInTextElements: 1
“𠆾𠇀𠇃”
Length: 6
LengthInTextElements: 3
As you can see, the string.Length property returns the number of 16-bit words (= .Net char structure) the string contains. To handle supplementary characters correctly in .Net, you need to use the StringInfo class.
Pingback: Length of UTF-8 VARCHAR in SQL Server | devioblog