System.Web Namespace HttpServerUtility Class
Encodes a string to be displayed in a browser.
1. HTML-encodes a string and returns the encoded string.
2. HTML-encodes a string and sends the resulting output to a TextWriter output stream.
The following example encodes a string for transmission by HTTP. It encodes the string named TestString, which contains the text "This is a <Test String>.", and copies it into the string named EncodedString as "This+is+a+%3cTest+String%3e.".
NOTE: This example shows how to use one of the overloaded versions of HtmlEncode. For other examples that might be available, see the individual overload topics.
[ VB ]
Dim TestString As String = "This is a <Test String>."
Dim writer As New StringWriter
Server.HtmlEncode ( TestString, writer )
Dim EncodedString As String = writer.ToString ( )
[ C# ]
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter ( );
Server.HtmlEncode ( TestString, writer );
String EncodedString = writer.ToString ( );
HttpServerUtility Members