JS全角转半角

2020-12-16  本文已影响0人  bryan_liu
const toCDB = function(str) {
  let tmp = "";
  for (let i = 0; i < str.length; i++) {
    if (str.charCodeAt(i) > 65248 && str.charCodeAt(i) < 65375) {
      tmp += String.fromCharCode(str.charCodeAt(i) - 65248);
    } else {
      tmp += String.fromCharCode(str.charCodeAt(i));
    }
  }
  return tmp
}
上一篇 下一篇

猜你喜欢

热点阅读