EDIT - Modified based on the answer:
okay here is what I modified based on the answer:
here is the string.
"November is Fruit's Fresh."
here is what I'm doing:
static string EscapeCharacters(string txt)
{
string encodedTxt = HttpUtility.HtmlEncode(txt);
return HttpUtility.HtmlDecode(encodedTxt);
}
string _decodedTxt = EscapeCharacters("November is Fruit's Fresh.");
when it returns I'm still getting the same text November is Fruit's Fresh.
END EDIT
I tried using HttpUtility.HtmlDecode
from System.Web
and also tried using SecurityElement.Escape
but it does not escapes anything correctly.
so I end-up writing my own replace method something like this:
static string EscapeXMLCharacters(string txt)
{
string _txt = txt.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace(""", "\"").Replace("'", "'").Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace(""", "\\").Replace("'", "'");
return _txt;
}
it does work in my situation but its hard to cover everything and in my situation I have some European characters like í``(í)
or é (é)
Is there a utility method built-in .Net that take cares of any special characters?