var str = "AB吉𠮷😁👨👩👧👦";
  var a = SplitToCharacters(str);

  static IEnumerable<string> SplitToCharacters(string input)
        {
            for (var i = 0; i < input.Length; ++i)
            {
                if (char.IsHighSurrogate(input[i]))
                {
                    int length = 0;
                    while (true)
                    {
                        length += 2;
                        if (i + length < input.Length && input[i + length] == 0x200D)
                        {
                            length += 1;
                        }
                        else
                        {
                            break;
                        }
                    }
                    yield return input.Substring(i, length);
                    i += length - 1;
                }
                else
                {
                    yield return input[i].ToString();
                }

            }
        }

 

posted on 2019-10-30 09:28  红磨坊后的白桦树  阅读(224)  评论(0编辑  收藏  举报