@Author:Outman
@Date:2022-10-28
1.中文符号转英文符号:
// 中文符号转英文符号
const charC2EUtil = (CNChar) => {let ENChar = CNChar// 转换引号类.replace(/[’|‘]/g, "'").replace(/[“|”]/g, '"')// 转换括号类.replace(/【/g, '[').replace(/】/g, ']').replace(/{/g, '{').replace(/}/g, '}')// 转换逗号、冒号.replace(/,/g, ',').replace(/:/g, ':')// 转换书名号、尖括号.replace(/《/g, '<').replace(/》/g, '>')// 转换句号、问号.replace(/。/g, '.').replace(/?/g, '?')// 转换叹号.replace(/!/g, '!')// 转换货币符号.replace(/¥/g, '$');return ENChar;
};
2.全角字符转半角字符:
// 半角字符转全角字符
const charH2FUtil = (hAngleChar) => {let fAngleChar = '';for (var i = 0; i < hAngleChar.length; i++) {/*** 特殊字符跳过处理:将对应的字符编码放入数组中* 例:65292为中文逗号,保留该符号不被转换*/if ([65292].indexOf(hAngleChar.charCodeAt(i)) > -1) {fAngleChar += String.fromCharCode(hAngleChar.charCodeAt(i));continue;}if (hAngleChar.charCodeAt(i) > 65248 && hAngleChar.charCodeAt(i) < 65375) {fAngleChar += String.fromCharCode(hAngleChar.charCodeAt(i) - 65248);} else {fAngleChar += String.fromCharCode(hAngleChar.charCodeAt(i));}}return fAngleChar;
};