如何在C#控制台窗口中显示泰米尔语文字“தமிழ்”?

时间:2018-11-03 06:21:40

标签: c# .net unicode console-application tamil

如下面的示例所示,我尝试了多种技术,通过将泰米尔文本解析为输出窗口来显示其unicode内容,但它不起作用。请提出建议,因为我要去哪里了?

private static void PrintInTamil1()
{
    const string str = "தமிழ்"; // this is already a unicode string.

    byte[] stringBytes = Encoding.Unicode.GetBytes(str);
    char[] stringChars = Encoding.Unicode.GetChars(stringBytes);

    foreach (var chr in stringChars)
    {
        // unicode character code
        var unicoded = ((int)chr).ToString();

        // hex character code
        var hexcoded = @"\u" + ((int)chr).ToString("X4").ToLower();

        Console.OutputEncoding = Encoding.UTF8;
        // print to VS output window
        Console.WriteLine(chr + "     " + unicoded + "     " + hexcoded);
    }
}

private static void PrintInTamil2()
{
    byte[] unicodeBytes = new byte[]
    {0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61,
     0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x70, 0x63,
     0x61, 0x70};

    string unicodeString = Encoding.UTF8.GetString(unicodeBytes);

    Console.WriteLine(unicodeString);
}        

private static void PrintInTamil()
{
    string str = "தமிழ்";
    var myarray2 = Encoding.UTF8.GetBytes(str);
    string unicodeString = Encoding.UTF8.GetString(myarray2);
    Console.WriteLine(unicodeString);
}

0 个答案:

没有答案