参考链接:所有英文符号转换成中文的符号
// 将英文标点转换成中文标点
chineseToEnglish(str) {
let tmp = "";
for (let i = 0; i < str.length; i++) {
if (str.charCodeAt(i) > 31 && str.charCodeAt(i) < 127) {
tmp += String.fromCharCode(str.charCodeAt(i) + 65248);
} else {
tmp += str[i];
}
}
return tmp;
},
把中文字符转换为英文可以参考:
参考链接
https://www.fanfanyu.com/news/staticpagefile/23176.html
https://www.fanfanyu.com/news/staticpagefile/23176.html
function qj2bj(str){
var tmp = "";
for(var i=0;i<str.length;i++){
if(str.charCodeAt(i) >= 65281 && str.charCodeAt(i) <= 65374){// 如果位于全角!到全角~区间内
tmp += String.fromCharCode(str.charCodeAt(i)-65248)
}else if(str.charCodeAt(i) == 12288){//全角空格的值,它没有遵从与ASCII的相对偏移,必须单独处理
tmp += ' ';
}else{// 不处理全角空格,全角!到全角~区间外的字符
tmp += str[i];
}
}
return tmp;
}
alert(qj2bj('??123123 ! !??!!??'));