Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize full-width and half-width conversion by JavaScript

Shulou Source: shulou.com Published: 2022-06-01 02:56:38 11月08日 Update

This article mainly introduces JavaScript how to achieve full-width half-width conversion, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Full-width half-width conversion / / iCase: 0 full-to-half, 1-and-a-half to full, other no conversion

Function chgCase (sStr, iCase) {

If (

Typeof sStr! = "string" | |

SStr.length full * /

For (I = 0; I)

< sStr.length; i += 1) { iCode = sStr.charCodeAt(i); if (iCode == 32) { iCode = 12288; } else if (iCode < 127) { iCode += 65248; } oRs.push(String.fromCharCode(iCode)); } } else { /*全->

Half * /

For (I = 0; I)

< sStr.length; i += 1) { iCode = sStr.charCodeAt(i); if (iCode == 12288) { iCode = 32; } else if (iCode >

65280 & & iCode < 65375) {

ICode-= 65248

}

ORs.push (String.fromCharCode (iCode))

}

}

Return oRs.join ("")

} Thank you for reading this article carefully. I hope the article "how to achieve full-width conversion of JavaScript" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles half-width full-width value interest at the same time more friends knowledge editing industry information information channels channels reference learning help support Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Microsoft macOS Linux Xiaomi