How do i get the decimal value of a unicode character in C#?

前端 未结 5 1143
南笙
南笙 2020-12-31 04:48

How do i get the numeric value of a unicode character in C#?

For example if tamil character (U+0B85) given, output should be 2949 (i.e. <

5条回答
  •  春和景丽
    2020-12-31 05:08

    This is an example of using Plane 1, the Supplementary Multilingual Plane (SMP):

    string single_character = "\U00013000"; //first Egyptian ancient hieroglyph in hex
    //it is encoded as 4 bytes (instead of 2)
    
    //get the Unicode index using UTF32 (4 bytes fixed encoding)
    Encoding enc = new UTF32Encoding(false, true, true);
    byte[] b = enc.GetBytes(single_character);
    Int32 code = BitConverter.ToInt32(b, 0); //in decimal
    

提交回复
热议问题