Js functions for full-width conversion

Source: Internet
Author: User

Copy codeThe Code is as follows:
/// The full-width space is 12288, and the half-width space is 32.
/// The relationship between the half-width (33-126) of other characters and the full-width (65281-65374) is as follows: the difference is 65248.
// Halfwidth conversion to fullwidth Function
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 the halfwidth function.
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. character (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.