转换为中文字符串
function f(data) {
if (data.length % 2) return '';
var tmp='';
for(i=0;i<data.length;i+=2){
tmp += '%' + data.charAt(i) + data.charAt(i+1);
}
return decodeURI(tmp);
}
转换为unicode编码
function toUnicode(val){
var strInput = val;
var nInputLength = strInput.length;
if(nInputLength%2 == 0) {//当输入够偶数位;
var StrHex = "";
for (var i=0; i < nInputLength; i = i + 2 ) {
var str = strInput.substr(i, 2); //16进制;
//StrHex = StrHex + .toString(16);
var n = parseInt(str, 16);//10进制;
StrHex = StrHex + String.fromCharCode(n);
}
return StrHex;
}
}
网友评论