How to display tamil text "தமிழ்" in c# console window?

1.2k Views Asked by At

As it is shown in below examples, i have tried various techniques to display tamil text by parsing its unicode content to the output window and it doesn't work. Please suggest as where i'm going wrong?

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

There are 0 best solutions below