代码之家  ›  专栏  ›  技术社区  ›  Dutow

C#和UTF-16字符

  •  7
  • Dutow  · 技术社区  · 16 年前

    string s = ""; // valid
    char c = ''; // generates a compiler error ("Too many characters in character literal")
    

    3 回复  |  直到 16 年前
        1
  •  10
  •   Emperor XLII    16 年前

    string char 在一个 表示UTF-16代码值。

    虽然没有BCL类型表示单个Unicode码位,但以方法重载的形式支持平面0以外的Unicode字符 字符串 GetUnicodeCategory  (char) System.Globalization.CharUnicodeInfo GetUnicodeCategory  (string,int)


    字符串 System.Globalization.StringInfo 类。这里,“文本元素”对应于屏幕上显示的单个字符。这意味着简单的字符( "a" "a\u0304\u0308" =“a”),以及代理配对( "\uD950\uDF21"

    GetTextElementEnumerator 字符串

        2
  •  4
  •   Joachim Sauer    16 年前

    documentation on char

    似乎确实 String string 能够处理这些字符。在一个 two surrogate characters .

        3
  •  3
  •   Luke Tigaris Luke Tigaris    16 年前

    例如:

    // iterating through a string NO UTF-32 SUPPORT
    for (int i = 0; i < sample.Length; ++i)
    {
        if (Char.IsDigit(sample[i]))
        {
            Console.WriteLine("IsDigit");
        }
        else if (Char.IsLetter(sample[i]))
        {
            Console.WriteLine("IsLetter");
        }
    }
    
    // iterating through a string WITH UTF-32 SUPPORT
    for (int i = 0; i < sample.Length; ++i)
    {
        if (Char.IsDigit(sample, i))
        {
            Console.WriteLine("IsDigit");
        }
        else if (Char.IsLetter(sample, i))
        {
            Console.WriteLine("IsLetter");
        }
    
        if (Char.IsSurrogate(sample, i))
        {
            ++i;
        }
    }