Export (0) Print
Expand All

HttpServerUtility.HtmlEncode Method

Encodes a string to be displayed in a browser.

Overload List

HTML-encodes a string and returns the encoded string.

[Visual Basic] Overloads Public Function HtmlEncode(String) As String
[C#] public string HtmlEncode(string);
[C++] public: String* HtmlEncode(String*);
[JScript] public function HtmlEncode(String) : String;

HTML-encodes a string and sends the resulting output to a TextWriter output stream.

[Visual Basic] Overloads Public Sub HtmlEncode(String, TextWriter)
[C#] public void HtmlEncode(string, TextWriter);
[C++] public: void HtmlEncode(String*, TextWriter*);
[JScript] public function HtmlEncode(String, TextWriter);


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.".

[Visual Basic] 
Dim TestString As String = "This is a <Test String>."
Dim writer As New StringWriter
Server.HtmlEncode(TestString, writer)
Dim EncodedString As String = writer.ToString()

String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlEncode(TestString, writer);
String EncodedString = writer.ToString();

String* TestString = S"This is a <Test String>.";
StringWriter* writer = new StringWriter();
Server->HtmlEncode(TestString, writer);
String* EncodedString = writer->ToString();

var testString : String = "This is a <Test String>."
var writer : StringWriter = new StringWriter()
Server.HtmlEncode(testString, writer)
var encodedString : String = writer.ToString()

See Also

HttpServerUtility Class | HttpServerUtility Members | System.Web Namespace

© 2015 Microsoft