C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
8,164 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello. I have a string that contains only one Chinese character. It's this character, U+24941.
In C#, its length is 2 instead of 1. So, if I write str[0]
, I get an illegal char.
I really need to split strings, that contain this kind of character, into single characters. How to correctly deal with this kind of string?
To enumerate the elements in case of .NET or Core, consider String.EnumerateRunes and the Rune class.
In case of .NET Framework, see StringInfo.GetTextElementEnumerator and other functions of StringInfo.