This article mainly introduces how to implement full-width-to-half-width conversion in javascript, involving techniques related to JavaScript string traversal and encoding conversion, for more information, see the example in this article. We will share this with you for your reference. The details are as follows:
Function fullChar2halfChar (str) {var result = ''; for (I = 0; I
= 65281 & code <= 65373) // In This unicode encoding range, all English letters have various characters {result + = String. fromCharCode (str. charCodeAt (I)-65248); // converts the unicode code of the full-width character to the unicode code of the corresponding half-width character} else if (code = 12288) // space {result + = String. fromCharCode (str. charCodeAt (I)-12288 + 32);} else {result + = str. charAt (I) ;}} return result ;}
I hope this article will help you design JavaScript programs.