WMLScript » URL » URL.escapeString

Syntax:
URL.escapeString(string)
string
The mandatory String parameter can be any string of characters in which you desire to replace all special characters with a hexadecimal escape sequence. This string can also be a URL.

Replaces special characters with hexadecimal escape sequences.

The URL.escapeString function replaces all special characters in the given string (including a URL string) with the appropriate hexadecimal escape sequences and returns the modified string. The modified string (URL) is said to be escaped.

The companion URL.unescapeString function replaces all hexadecimal escape sequences with the appropriate special characters.

A hexadecimal escape sequence is composed of a mandatory percent sign followed immediately by the two-digit hexadecimal number (i.e., %2A). There are sixteen hexadecimal numbers: 1 2 3 4 5 6 7 8 9 0 A B C D E F (or a b c d e f)

Here is a list of special characters that can be escaped for a URL.
Please refer to: RFC2396 Uniform Resource Identifiers (URI): Generic Syntax.

Character Escape Sequence
control key see footnote 1
blank space %20
; %3B
/ %2F
? %3F
@ %40
%26
= %3D
+ %2B
$ %24
, %2C
( see footnote 2
) see footnote 2
| %7C
\ %5C
^ %5E
[ %5B
] %5D
' %27
%3C
%3E
# %23
% %25
* %22


1. A URL cannot contain control characters.
2. The ( and ) were not escaped by the Nokia simulator.

Examples

Code:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.WAPforum.org/DTD/wml_1.1.xml">
<wml>

<card id="card1">
   <p>
   escapeString example
   </p>
   <do type="accept">
      <go href="EscapeStringExample.wmls#findescapestring()" />
   </do>
</card>

<card id="card2">
<p>
   original string = $(original)
   <br />
   escape string = $(escape)
</p>
</card>

</wml>
Explanation:

Code for EscapeStringExample.wml

Language(s): WML
Code:
extern function findescapestring()
{
   var str = Dialogs.prompt("Enter string or URL", "");
   var esc = URL.escapeString(str);
   WMLBrowser.setVar("original", str);
   WMLBrowser.setVar("escape", esc);
   WMLBrowser.go("EscapeStringExample.wml#card2");
};
Explanation:

Code for EscapeStringExample.wmls

Language(s): WML

See Also: