["..G$ ","","FGKqQou &amp; me &gt; themQNot HTML encodedQKKYou & me > themKKQIs HTML encodedQKKYGQHtmlEncode and HtmlDecode methods: C#QKKusing System;Kusing System.Net;KKclass ProgramK{KFstatic void Main()KF{KFFstring a = WebUtility.QHtmlEncodeQ(q<html><head><title>T</title></head></html>q);KFFstring b = WebUtility.QHtmlDecodeQ(a);KKFFConsole.WriteLine(qAfter HtmlEncode: q + a);KFFConsole.WriteLine(qAfter HtmlDecode: q + b);KF}K}KKQKKAfter HtmlEncode:K&lt;html&gt;&lt;head&gt;&lt;title&gt;T&lt;/title&gt;&lt;/head&gt;&lt;/html&gt;KKAfter HtmlDecode:K<html><head><title>T</title></head></html>QASPX code-behind file that encodes HTML: C#QKKusing System;Kusing System.IO;Kusing System.Web;Kusing System.Web.UI;KKpublic partial class _Default : PageK{KFprotected void Page_Load(object sender, EventArgs e)KF{QKFF// This could mess up HTML.KFFQstring text = qyou & me > themq;Q // 1KKFF// Replace > with >KFFQstring htmlEncoded = Server.HtmlEncode(text);Q // 2KKFF// Now has the > again.KFFQstring original = Server.HtmlDecode(htmlEncoded);Q // 3KKFF// This is how you can access the Server in any class.KFFQstring alsoEncoded = HttpContext.Current.Server.HtmlEncode(text);Q // 4KKFFQStringWriter stringWriter = new StringWriter();KFFusing (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))KFF{QKFFF// Write a DIV with encoded text.KFFFQwriter.RenderBeginTag(HtmlTextWriterTag.Div);KFFFwriter.WriteEncodedText(text);KFFFwriter.RenderEndTag();KFF}KFFstring html = stringWriter.ToString();Q // 5KFQ}K}KKQNotesQKKStep 1: QBefore encoding has occurred.QKString: you & me > themKKStep 2: QThe string is encoded for HTML.QKString: yGKKStep 3: QString is converted back from HTML.QKString: you & me > themKKStep 4: QThe string is encoded for HTML again.QKString: yGKKStep 5: QThe HTML string is written into a DIV.QKText: <div>yG</div>Q","A(rEABXPF(C|F77}.P6666666F884*CE(XB.CE","HtmlEncode, HtmlDecode."," HTML must sometimes be encoded. This is necessary for it to be displayed as text in another HTML document. With the WebUtility.HtmlEncode and WebUtility.HtmlDecode methods in the C# language, we do this without writing any custom code. ","Example."," The HtmlEncode method is designed to receive a string that contains HTML markup characters such as > and <. The HtmlDecode method, meanwhile, is designed to reverse those changes. It changes encoded characters back to actual HTML. ","Next: ","We use HtmlEncode and HtmlDecode in a C# program. The System.Net assembly is included at the top of the program.","Example 2."," Next, HtmlEncode and HtmlDecode are also built into the Server objects in ASP.NET. These methods have no advantages over the HttpUtility methods. They are equivalent. We present an example that uses them in a Page class. ","In this example,"," we see three different methods. The first two just return an encoded or decoded string, and the HtmlTextWriter uses an interesting method called WriteEncodedText. ","This may be more efficient, as it could avoid a string copy. I tested these methods with breakpoints.","HtmlTextWriter ","htmltextwriter","The WebUtility class"," is a better way to encode HTML and URLs in programs. You will want to call WebUtility.HtmlDecode and WebUtility.HtmlEncode on your strings. It is also possible to use the HttpUtility class.","Performance."," In my brief benchmarks, I found Server.HtmlEncode and Server.HtmlDecode to be much faster than my home-grown version that used StringBuilder. Unless you want create a better implementation, it is best to use these Framework methods. ","StringBuilder ","stringbuilder","Summary."," These methods provide reliable replacement of HTML characters and are available in all your .NET programs. HtmlEncode and HtmlDecode also handle character entities. These are sequences that represent non-ASCII characters. ","These methods are also available on the HttpUtility type. More information on the HttpUtility type is available.","HttpUtility ","httputility"]

%iVBORw0KG;)NSUhEUg?ANo)vCAM?ACynCRD)GFBMVEX::x/vrd:Cs3ffI5fzh8f3D7/N+xvnhyvu1?AC5UlEQVR4Xs3X4W7rMAgFYB+wnfd/4ztdSzkzJaMko9r5iTD2tzJVbW8Go/c+RrMZ/+urMH5M25uaG7+F1xdkHCvd1PVYGexxwqOdBYXrgrJl2Ou1gNYvZn9/d49oVu/atg5e/6dpavT+Q/uHaYBLA3DSAMQ024JmA7K4kUAVDSKiDk2+ctLYcxXFS0u3MpmGxuv/LM3q/ZfSUE9DhibKnI9f6V+Box92PY40DfdgemiCxnCvpqzYMe5GkqBv0/R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