JS Full half angle conversion

Source: Internet
Author: User

/*
* Full-angle space is 12288, half a corner space is 32
* The corresponding relation of the other character half angle (33-126) and the whole angle (65281-65374) is: The difference is 65248
*/

function SBC (text) {
Return Text.replace (/[x20-x7e]/g, function ($) {
return $ = = ""? u3000 ": String.fromCharCode ($.charcodeat (0) + 0xfee0);
});
}
var todbc=function (input) {//to DBC case
var res= "", C;
for (var i=0;i< input.length;i++) {
C=input.charcodeat (i);
if (c >=0xff01 && C <=0xff5e)//65281 65374
Res+=string.fromcharcode (C-0XFEE0);//65248
else if (c==0x3000)//12288
Res+=string.fromcharcode (0x20);//32
Else
Res+=input.charat (i);
}
return res;
}
var tosbc=function (input) {//to SBC case
var res= "", C;
for (Var i=0 i < input.length;i++) {
C=input.charcodeat (i);
if (c>=0x21 && c<=0x7e)//33 126
Res+=string.fromcharcode (C+0XFEE0);
else if (c==0x20)
res = String.fromCharCode (0x3000);
Else
res = Input.charat (i);
}
return res;
}
var s= ", oh Oh, hello ssss! #~ ";
var s1=todbc (s);
var s2=tosbc (S1);
Alert ("Original character:" +s+ "NNTODBC:" +s1+ "NNTOSBC:" +S2);

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.