Does C# have something like PHP's mb_convert_encoding()?

前端 未结 3 483
遇见更好的自我
遇见更好的自我 2021-01-16 05:46

Is there a way on C# that I can convert unicode strings into ASCII + html entities, and then back again? See, in PHP, I can do it like so:



        
3条回答
  •  感动是毒
    2021-01-16 06:27

    Here are some examples of conversions. The first two show how to convert, the last one can be turned into a function that takes two encoding names as strings, and convert.

    A list of encoding names can be found here.

    Encoding.UTF8.GetString(Encoding.ASCII.GetBytes(str));
    Encoding.UTF8.GetString(Encoding.Unicode.GetBytes(str));
    Encoding.GetEncoding("UTF-8").GetString(Encoding.GetEncoding("ASCII").GetBytes(str));
    

提交回复
热议问题