CSharp examples for System.Web:Web Page
Html Encode
using System.Net; using System.IO;//from w w w. jav a 2 s . c o m using System.Text.RegularExpressions; using System.Web; using System.Text; using System.Collections.Generic; using System; public class Main{ public static string HtmlEncode(string str) { if (str == null) { return string.Empty; } string chrChang; str = HttpUtility.HtmlEncode(str); str = str.Replace("<", "<"); str = str.Replace(">", ">"); str = str.Replace("&", "&"); chrChang = ((char)13).ToString(); str = str.Replace(chrChang, "<br/>"); chrChang = ((char)34).ToString(); str = str.Replace(chrChang, """); chrChang = ((char)32).ToString(); str = str.Replace(chrChang, " "); chrChang = ((char)10).ToString(); str = str.Replace(chrChang, string.Empty); return str; } }