Unicode-to-string conversion in C#

前端 未结 7 954
你的背包
你的背包 2020-12-20 17:22

How can I convert a Unicode value to its equivalent string?

For example, I have \"రమెశ్\", and I need a function that accepts this Unicode value and returns a string

7条回答
  •  别那么骄傲
    2020-12-20 18:14

    There are different types of encoding. You can try some of them to see if your bytestream get converted correctly:

    System.Text.ASCIIEncoding encodingASCII = new System.Text.ASCIIEncoding();
    System.Text.UTF8Encoding encodingUTF8 = new System.Text.UTF8Encoding();
    System.Text.UnicodeEncoding encodingUNICODE = new System.Text.UnicodeEncoding();
    
    var ascii = string.Format("{0}: {1}", encodingASCII.ToString(), encodingASCII.GetString(textBytesASCII));
    var utf =   string.Format("{0}: {1}", encodingUTF8.ToString(), encodingUTF8.GetString(textBytesUTF8));
    var unicode = string.Format("{0}: {1}", encodingUNICODE.ToString(), encodingUNICODE.GetString(textBytesCyrillic));
    

    Have a look here as well: http://george2giga.com/2010/10/08/c-text-encoding-and-transcoding/.

提交回复
热议问题