Javascript implements full-width-to-half-width conversion, and javascript full-width conversion

Source: Internet
Author: User

Javascript implements full-width-to-half-width conversion, and javascript full-width conversion

This article describes how to implement full-width and half-width conversion in javascript. We will share this with you for your reference. The details are as follows:

Function fullChar2halfChar (str) {var result = ''; for (I = 0; I <str. length; I ++) {code = str. charCodeAt (I); // obtain the unicode code of the current character if (code >=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.

Articles you may be interested in:
  • Javascript method for full-width half-width Detection
  • Javascript converts fullwidth and halfwidth characters
  • JavaScript fullwidth to halfwidth
  • Js functions for full-width conversion
  • Asp (javascript) full-width half-width conversion code dbc2sbc
  • Js determines the browser type and closes the current window automatically when the width and space of the browser are removed.

Related Article

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.