/**
* URL编码,encoding为空时应用统一的UTF-8编码处理,可设"GB2312"、"UTF-8"等,(兼容性处理,对应JS中的escape)
*/
public static function UrlEncode(str:String,encoding:String = ""):String
{
if (str == null || str == "")
{
return "";
}
if (encoding == null || encoding == "")
{
return encodeURI(str);
}
var returnValue:String = "";
var byte:ByteArray =new ByteArray();
byte.writeMultiByte(str,encoding);
for (var i:int; i<byte.length; i++)
{
returnValue += escape(String.fromCharCode(byte[i]));
}
return returnValue;
}
/**
* URL解码,encoding为空时应用统一的UTF-8编码处理,可设"GB2312"、"UTF-8"等,(兼容性处理,对应JS中的unescape)
*/
public static function UrlDecode(str:String,encoding:String = ""):String
{
if (str == null || str == "")
{
return "";
}
if (encoding == null || encoding == "")
{
return decodeURI(str);
}
var returnValue:String = "";
var byte:ByteArray =new ByteArray();
byte.writeMultiByte(str,encoding);
for (var i:int; i<byte.length; i++)
{
returnValue += unescape(String.fromCharCode(byte[i]));
}
return returnValue;
}