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
}