I have a string which I'm html encoding, then using a string builder to allow certain html characters. All works fine except for the left sided quote ‘. Any ideas what I'm doing wrong?

StringBuilder htmlStr = new StringBuilder(); htmlStr.Append(HttpUtility.HtmlEncode(reader["NewsDetail"])); htmlStr.Replace("&lt;p&gt;", "<p>"); htmlStr.Replace("&lt;/p&gt;", "</p>"); htmlStr.Replace("&lsquo;", "‘"); 
6

1 Answer

This char is not encoded by HtmlEncode.

string h = HttpUtility.HtmlEncode("<p>‘test’</p>"); Console.WriteLine(h); // output: &lt;p&gt;‘test’&lt;/p&gt; 

If you need to encode you will have to do it yourself. Check this post: HttpUtility.HtmlEncode doesn't encode everything

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.