Return to Snippet

Revision: 24952
at March 16, 2010 15:47 by adrianparr


Initial Code
var myString:String = "/";
trace(myString);
var urlEncodeForwardSlashedRegExp:RegExp = new RegExp("/", "gi");
myString = myString.replace(urlEncodeForwardSlashedRegExp, "%2F");
trace(myString);

// OUTPUT
// /
// %2F

Initial URL

                                

Initial Description
In AS2 forward slashes got url-encoded to %2F when you escaped them. But in AS3 they get ignored and left as they are. In some situations I have found that this can cause problems. So you can do it manually using this regular expression.

Initial Title
AS3 Convert a Forward Slash to URLEncoded Character %2F

Initial Tags
regex, replace, regexp

Initial Language
ActionScript 3