System.Web Namespace HttpServerUtility Class
HTML-encodes a string and returns the encoded string.
[ VB ]
Overloads Public Function HtmlEncode ( _
ByVal s As String _
) As String
[ C# ]
public string HtmlEncode (
string s
);
[ C++ ]
public: String* HtmlEncode (
String* s
);
[ JScript ]
public function HtmlEncode (
s : String
) : String;
- s
- The text string to encode.
The HTML-encoded text.
URL encoding ensures that all browsers will correctly transmitted text in URL strings. Characters such as "?", "&", "/", and spaces may be truncated or corrupted by some browsers so those characters cannot be used in ASP.NET pages in "<A>" tags or in querystrings where the strings may be sent by a browser in a request string.
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 EncodedString As String = Server.HtmlEncode ( TestString )
[ C# ]
String TestString = "This is a <Test String>.";
String EncodedString = Server.HtmlEncode ( TestString );
HttpServerUtility Members HttpServerUtility.HtmlEncode Overload List