CSharp examples for System:String HTML
Escapes the string for showing as HTML. Converts enters to <br>, '<' to '<' etc.
using System.Xml.Serialization; using System.Collections; using System.Globalization; using System.Collections.Specialized; using System.Text; using System.Collections.Generic; using System;//from w w w. j av a2 s . c o m public class Main{ /// <summary> /// Escapes the string for showing as HTML. /// Converts enters to <br/>, '<' to '&lt;' etc. /// </summary> /// <param name="txt">The Text to be escaped.</param> /// <returns></returns> public static string EscapeStringForHTML(string txt) { string res = txt; string[] escapeFrom = new string[] { "<", ">", "\n" }; string[] escapeTo = new string[] { "<", ">", "<br/>" }; for (int i = 0; i < escapeFrom.Length; ++i) res = res.Replace(escapeFrom[i], escapeTo[i]); return res; } }