一个不错的字符串转码解码函数(自写)
functionisString(variable){
returnObject.prototype.toString.call(variable).indexOf('String')!=-1;
}
functionisNumeric(variable){
return!isNaN(parseFloat(variable))&&isFinite(variable);
}
functionstringEncode(string){
string=isString(string)||isNumeric(string)?String(string):'';
varcode,
i=0,
code_string='',
len=string.length;
while(i<string.length){
code=string.charCodeAt(i);
code_string+=''+String(code).length+code;
i++;
}
returncode_string;
}
functionstringDecode(code){
vari=0,
code_len,
decode_string='';
code=String(code);
while(i<code.length){
code_len=+code.charAt(i);
i++;
decode_string+=String.fromCharCode(+code.substr(i,code_len));
i+=code_len;
}
returndecode_string;
}热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短