Converting HTML entities to Unicode Characters in C#

前端 未结 6 2083
心在旅途
心在旅途 2020-12-15 15:23

I found similar questions and answers for Python and Javascript, but not for C# or any other WinRT compatible language.

The reason I think I need it, is because I\'

6条回答
  •  攒了一身酷
    2020-12-15 15:56

    Different coding/encoding of HTML entities and HTML numbers in Metro App and WP8 App.

    With Windows Runtime Metro App

    {
        string inStr = "ó";
        string auxStr = System.Net.WebUtility.HtmlEncode(inStr);
        // auxStr == ó
        string outStr = System.Net.WebUtility.HtmlDecode(auxStr);
        // outStr == ó
        string outStr2 = System.Net.WebUtility.HtmlDecode("ó");
        // outStr2 == ó
    }
    

    With Windows Phone 8.0

    {
        string inStr = "ó";
        string auxStr = System.Net.WebUtility.HtmlEncode(inStr);
        // auxStr == ó
        string outStr = System.Net.WebUtility.HtmlDecode(auxStr);
        // outStr == ó
        string outStr2 = System.Net.WebUtility.HtmlDecode("ó");
        // outStr2 == ó
    }
    

    To solve this, in WP8, I have implemented the table in HTML ISO-8859-1 Reference before calling System.Net.WebUtility.HtmlDecode().

提交回复
热议问题