I want to convert &
to &, "
to " etc.
Is there a function in c# that could do that without writing all the options manually?
System.Web.HttpUtility.HtmlDecode()
Edit: Note from here that "To encode or decode values outside of a web application, use..."
System.Net.WebUtility.HtmlDecode()
Use the static method
HttpUtility.HtmlEncode
to change &
to &
and "
to "
. Use
HttpUtility.HtmlDecode
to do the reverse.
Corredera Romain
You can use System.Net.WebUtility.HtmlDecode(uri);
A good article about this subject : Different ways how to escape an XML string in C#
Alex W.
using System.Web;
...
var html = "this is a sample & string";
var decodedhtml = HttpUtility.HtmlDecode(html);
For .NET < 4 simple encoder
public static string HtmlEncode(string value)
{
return value.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'");
}
来源:https://stackoverflow.com/questions/1562360/converting-amp-to-etc