Name
Escape Function
Syntax
Escape (string)string
- result
Use: Optional
Data Subtype: String
The String to be encoded.
Return Value
An encoded Variant of Subtype string.
Description
Returns an encoded version of string
Rules at a Glance
All spaces, puncuation characters, accented characters, and non-ASCII charaters are replaced with the character substring
%xx, wherexxis the hexidecimal number that represents the character. For example, a space is replaced by%20.Unicode characters with a value greater than 255 are replaced with the character substring
%uxxxx, wherexxxxis the hexidecimal number that represents the character.
Programming Notes
The Escape function is not documented in the VBScript documentation.
The function corresponds to the JavaScript escape method.
You can use the Escape function to encode an HTML document so that a web browser displays the HTML source rather than interprets it.
You can use the Escape function to encode an HTTP query string before returning it to a web server.
If
stringcontains no spaces, puncuation characters, accented characters, or non-ASCII characters, the Escape function simply returnsstringunchanged.
Example
The following is a very simple routine that allows you to experiment with encoding character strings:
Option Explicit
Dim sIn, sOut
Do While True
sIn = InputBox("Enter a string:", "UnescapedString", "")
If sIn = " Then Exit Do
sOut = Escape(sIn)
msgbox "In: " & sIn & vbcrlf & _
LoopFor example, the string:
This is a level-1 head: <H1>Hello!</H1> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access