Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 5x 5x 54x 54x 1x 53x 46x 7x 5x | /** * 转换为半角字符串。 * * @param value 要转换的字符串 * @returns 返回转换后的半角字符串 */ export function toHalfWidthString(value: string): string { let result = '' for (let i = 0; i < value.length; i++) { const charCode = value.charCodeAt(i) if (charCode === 12288) { result += String.fromCharCode(32) } else if (charCode > 65280 && charCode < 65375) { result += String.fromCharCode(charCode - 65248) } else { result += String.fromCharCode(charCode) } } return result } |