Convert to & etc

I want to convert & in &, " in "ect. Is there a function in C # that can do this without writing all the parameters manually?

+42
c # html-encode string-conversion
Oct 13 '09 at 19:19
source share
6 answers
 System.Web.HttpUtility.HtmlDecode() 
+72
Oct 13 '09 at 19:23
source share

Use static method

 HttpUtility.HtmlEncode 

to change & to & and " on " Use

 HttpUtility.HtmlDecode 

do the opposite.

+20
Oct 13 '09 at 19:28
source share

You can use System.Net.WebUtility.HtmlDecode(uri);

+16
Jun 02 '14 at 13:08
source share
+4
Oct 13 '09 at 19:23
source share
+4
Jul 12 '11 at 15:06
source share

For .NET <4 simple encoders

  public static string HtmlEncode(string value) { return value.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace("\"", "&quot;").Replace("'", "&apos;"); } 
-four
Apr 15 '14 at 19:40
source share



All Articles