asp.net.ph

Server.HtmlEncode Method ( String, TextWriter )

System.Web Namespace   HttpServerUtility Class


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

[ VB ]
Overloads Public Sub HtmlEncode ( _
   ByVal s As String, _
   ByVal output As TextWriter _
)

[ C# ]
public void HtmlEncode (
   string s,
   TextWriter output
);

[ C++ ]
public: void HtmlEncode (
   String* s,
   TextWriter* output
);

[ JScript ]
public function HtmlEncode (
   s : String,
   output : TextWriter
);

Parameters

s
The string to encode.
output
The TextWriter output stream containing the encoded string.

Remarks

HTML encoding ensures that text will be correctly displayed in the browser, not interpreted by the browser as HTML. For example, if a text string contains "<" or ">" characters, the browser would interpret these characters as part of HTML tags. The HTML encoding of these two characters is "&lt" and "&gt", respectively, which causes the browser to display the angle brackets correctly.

Example

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

[ 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 ( );
   
See Also

HttpServerUtility Members   HttpServerUtility.HtmlEncode Overload List Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph