HttpUtility.JavaScriptStringEncode Method
Encodes a string.
This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.
| Name | Description | |
|---|---|---|
|
JavaScriptStringEncode(String) | Encodes a string. |
|
JavaScriptStringEncode(String, Boolean) | Encodes a string. |
This method encodes strings. For instance, single quotation marks and double quotation marks are included as \' and \" in the encoded string.
URL encoding makes sure that all browsers correctly transmit text in URL strings. Characters such as a question mark (?), ampersand (&), slash (/), and spaces might be truncated or corrupted by some browsers. Therefore, these characters must be encoded in a elements or in query strings where the strings can be re-sent by a browser in a request string.
Incorrect remarks
Contrary to what is stated in the remarks, apostrophes (single quotes) are not encoded as \'. Double quotes are encoded as \". (I am running .Net 4 if that makes difference?)
HttpUtility.JavaScriptStringEncode("Arby's") == "Arby\\u0027s"
HttpUtility.JavaScriptStringEncode("Arby\"s") == "Arby\\\"s"
HttpUtility.JavaScriptStringEncode("Arby's") == "Arby\\u0027s"
HttpUtility.JavaScriptStringEncode("Arby\"s") == "Arby\\\"s"
- 8/18/2011
- chrisfewtrell
- 10/31/2011
- Thomas Lee