function convertToHalfWidth(str) {
return str.replace(/[\uff01-\uff5e]/g, function(match) {
var charCode = match.charCodeAt(0) - 0xfee0;
return String.fromCharCode(charCode);
});
}
var fullwidthString = "and";
var halfwidthString = convertToHalfWidth(fullwidthString);
console.log(halfwidthString); // 输出 "and"
js 将全角字符转换为半角字符 方法
最新推荐文章于 2025-04-01 10:43:54 发布