How to deal with multi-char character?

CCC 21 Reputation points

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?

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.
10,621 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 114.5K Reputation points

    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.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful