Escape text for HTML

后端 未结 9 916
别那么骄傲
别那么骄傲 2020-11-28 04:50

How do i escape text for html use in C#? I want to do

sample=\"blah\"

and have

blah&l         


        
9条回答
  •  醉话见心
    2020-11-28 05:37

    there are some special quotes characters which are not removed by HtmlEncode and will not be displayed in Edge or IE correctly like ” and “ . you can extent replacing these characters with something like below function.

    private string RemoveJunkChars(string input)
    {
        return HttpUtility.HtmlEncode(input.Replace("”", "\"").Replace("“", "\""));
    }
    

提交回复
热议问题