function UrlDecode(str) {
str = StringReplaceAll(str, "\\", " ");
str = unescape(str);
return (str);
}
function UrlEncode(str) {
str = escape(str);
str = StringReplaceAll(str, "\\", "%2B");
str = StringReplaceAll(str, "%20", "+");
return (str);
}
function StringReplaceAll(source, find, replacement) {
return (source.split(find).join(replacement));
}
后来发现as3自带了个方法,很实用
encodeURI()
将字符串编码为有效的 URI(统一资源标识符)。 将完整的 URI 转换为一个字符串,其中除属于一小组基本字符的字符外,其它所有字符都编码为 UTF-8 转义序列。
下表显示不会 由 encodeURI
函数转换为 UTF-8 转义序列的基本字符的整个集合。
未编码的字符 |
---|
0 1 2 3 4 5 6 7 8 9 |
a b c d e f g h i j k l m n o p q r s t u v w x y z |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z |
; / ? : @ & = + $ , # |
- _ . ! ~ * ' ( ) |
自带的代码例子
package {
import flash.display.Sprite;
public class EncodeURIExample extends Sprite {
public function EncodeURIExample() {
var uri:String = "http://www.example.com/application.jsp?user=<user name='some user'></user>";
var encoded:String = encodeURI(uri);
var decoded:String = decodeURI(encoded);
trace(uri); // http://www.example.com/application.jsp?user=<user name='some user'></user>
trace(encoded); // http://www.example.com/application.jsp?user=%3Cuser%20name='some%20user'%3E%3C/user%3E
trace(decoded); // http://www.example.com/application.jsp?user=<user name='some user'></user>
}
}
}