Let's go to the code first, talk nonsense ^_^
Copy Code code as follows:
/**
* Turn full angle character
*/
function Todbc (str) {
var result = "";
var len = str.length;
for (Var i=0;i<len;i++)
{
var ccode = str.charcodeat (i);
Difference between Full-width and half-width (extra space): 65248 (decimal)
Ccode = (ccode>=0x0021 && ccode<=0x007e)? (Ccode + 65248): Ccode;
Working with spaces
Ccode = (ccode==0x0020)? 0x03000:ccode;
result = String.fromCharCode (Ccode);
}
return result;
}
/**
* Turn Half-width characters
*/
function TOSBC (str) {
var result = "";
var len = str.length;
for (Var i=0;i<len;i++)
{
var ccode = str.charcodeat (i);
Difference between Full-width and half-width (extra space): 65248 (decimal)
Ccode = (ccode>=0xff01 && ccode<=0xff5e)? (cCode-65248): Ccode;
Working with spaces
Ccode = (ccode==0x03000)? 0x0020:ccode;
result = String.fromCharCode (Ccode);
}
return result;
}
Knowledge points
By comparing Half-width characters with full-width characters (ASCII characters), we can find the range of ASCII characters with Full-width and Half-width points: 0x20~0x7e.
Like what:
Total angle difference of symbol half angle
# 0x0023 0xff03 0xfee0
? 0x003f 0xff1f 0xfee0
Space 0x0020 0x03000 0X2FE0
In addition to space, the other characters, the full and half of the difference between the angle: 0xffe0
Therefore, in the Full-width and half-width character conversion, special handling of space is needed.
For example:
Full angle = half angle + 0xfee0
Half angle = Full angle-0xffe0