Why I get a different result with the same HtmlDecode() function?

后端 未结 2 614
忘了有多久
忘了有多久 2020-12-22 01:06

This is my code :

string myText = \"Wählen Sie bitte\";
string myTextDecoded = HttpUtility.HtmlDecode(myText);
Response.Write(myTextDecoded);
ddAdul         


        
2条回答
  •  太阳男子
    2020-12-22 01:54

    You can write both variants in HTML and both will work fine (as long as the document is properly encoded). Both examples will produce the same (valid) HTML and output:

    Wählen
    Wählen
    

    Unencoded Umlauts are not invalid. They are equivalent to their encoded versions.

    But if you don't encode them your page's encoding must support German characters. UTF-8 does.

    Why do the two variants result in different HTML? Response.Write does not encode its output so you can output HTML like "x". ListItems encode their text because you cannot output HTML in them anyway. It would make no sense to pass through unencoded text.

提交回复
热议问题