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("<p>", "<p>");
htmlStr.Replace("</p>", "</p>");
htmlStr.Replace("‘", "‘");
1 Answer
This char is not encoded by HtmlEncode.
string h = HttpUtility.HtmlEncode("<p>‘test’</p>");
Console.WriteLine(h);
// output: <p>‘test’</p>
If you need to encode you will have to do it yourself. Check this post: HttpUtility.HtmlEncode doesn't encode everything