JavaScript digital full-width half-width conversion, javascript full-width half-width
</Pre> <pre name = "code" class = "javascript"> // The full-width space is 12288, and the half-width space is 32 // other characters (33-126) the ing with the fullwidth (65281-65374) is: the difference is 65248 // The halfwidth is converted to the fullwidth function ToDBC (txtstring) {var tmp = ""; for (var I = 0; I <txtstring. length; I ++) {if (txtstring. charCodeAt (I) = 32) {tmp = tmp + String. fromCharCode (12288);} if (txtstring. charCodeAt (I) <127) {tmp = tmp + String. fromCharCode (txtstring. charCodeAt (I) + 65248) ;}return tmp ;}// returns to the halfwidth function ToCDB (str) {var tmp = ""; for (var I = 0; I <str. length; I ++) {if (str. charCodeAt (I)> 65248 & str. charCodeAt (I) <65375) {tmp + = String. fromCharCode (str. charCodeAt (I)-65248);} else {tmp + = String. fromCharCode (str. charCodeAt (I);} return tmp}