FUNCTION:  URL.escapeString

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.
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.
Code for EscapeStringExample.wml
<?xml version="1.0"?>

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

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


Code for EscapeStringExample.wmls
extern function findescapestring()
   var str = Dialogs.prompt("Enter string or URL", "");
   var esc = URL.escapeString(str);
   WMLBrowser.setVar("original", str);
   WMLBrowser.setVar("escape", esc);

Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information