How to deal with multi-char character?

CCC 21 Reputation points
2022-04-04T13:45:17.937+00:00

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?

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

Accepted answer
  1. Viorel 114.5K Reputation points
    2022-04-04T14:02:54.267+00:00

    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