How to decode UTF8 bytes?

后端 未结 2 1724
天涯浪人
天涯浪人 2021-01-23 01:15

How can I decode UTF8 bytes in a string in C#?

Example: Decode this input:

\"Poluci%C3%B3n\"

To output this:

\"Polu         


        
相关标签:
2条回答
  • 2021-01-23 01:45

    This encoding appears to be URL encoding (not UTF-8 encoding). You can unencode it with a number of different methods in .NET:

    HttpUtility.UrlDecode("Poluci%C3%B3n"); // returns "Polución"
    Uri.UnescapeDataString("Poluci%C3%B3n"); // returns "Polución"
    
    0 讨论(0)
  • 2021-01-23 01:56

    Try this:

    Uri.UnescapeDataString("Poluci%C3%B3n")
    

    the problem has nothing to do with UTF8 though. It's just URL encoded.

    0 讨论(0)
提交回复
热议问题