JavaScript digital full-width half-width conversion, javascript full-width half-width

Source: Internet
Author: User

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}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.