How to Replace ‘
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...
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