81,092
社区成员
发帖
与我相关
我的任务
分享
function replace_CDB(text) {
return text && text.replace(/[\u3000\uff01-\uff5f]/g, function($0) {
return $0 == "\u3000" ? " " : String.fromCharCode($0.charCodeAt(0) - 0xfee0);
});
}
function replace_DBC(text) {
return text && text.replace(/[\x20-\x75]/g, function($0) {
return $0 == " " ? "\u3000" : String.fromCharCode($0.charCodeAt(0) + 0xfee0);
});
}
function ToCDB(str){
var tmp = "" , codeAt = "";
for(var i=0;i<str.length;i++){
codeAt = str.charCodeAt(i);
if(codeAt>65248 && codeAt<65375){
tmp += String.fromCharCode(codeAt-65248);
} else if(codeAt == 12288){
tmp += String.fromCharCode(32);
} else{
tmp += String.fromCharCode(codeAt);
}
}
return tmp
}
function ToDBC(str){
var tmp = "", codeAt = "";
for(var i=0;i<str.length;i++){
codeAt = str.charCodeAt(i);
if(codeAt > 32 && codeAt < 127){
tmp += String.fromCharCode(codeAt+65248);
} else if(codeAt == 32){
tmp += String.fromCharCode(12288);
} else {
tmp += String.fromCharCode(codeAt);
}
}
return tmp;
}