I have characters incoming from an xml template for example:
& >
Does a generic function exist in the framework to replace these with their normal equivalents?
I have characters incoming from an xml template for example:
& >
Does a generic function exist in the framework to replace these with their normal equivalents?
You want to use HttpUtility.HtmlDecode
.:
Converts a string that has been HTML-encoded for HTTP transmission into a decoded string.
The above answer is fantastic, though it is in System.Web, so I thought I'd just give something that would suffice for a forms or console app, though if there is anything better than just writing it out explicitly, I am just as curious.
private string ReplaceSpecialCharacters(string Input)
{
Input = Regex.Replace(Input, "&", "&");
Input = Regex.Replace(Input, "'", "'");
Input = Regex.Replace(Input, """, "\"");
Input = Regex.Replace(Input, "‹", "<");
Input = Regex.Replace(Input, "›", ">");
Input = Regex.Replace(Input, ">", ">=");
Input = Regex.Replace(Input, "<", "<=");
return Input;
}