Halfwidth to fullwidth:
C = "Hello world". tochararray ();
For (INT I = 0; I <C. length; I ++)
{
Byte [] B = system. Text. encoding. Unicode. getbytes (C, I, 1 );
If (B. Length = 2)
{
If (B [1] = 0)
{
B [0] = (byte) (B [0]-32 );
B [1] = 255;
C [I] = system. Text. encoding. Unicode. getchars (B) [0];
}
}
}
String strnew = new string (C );
Fullwidth to halfwidth:
String qjstr = "Hello, amigo quanjiao character ";
Char [] C = qjstr. tochararray ();
For (INT I = 0; I <C. length; I ++)
{
Byte [] B = system. Text. encoding. Unicode. getbytes (C, I, 1 );
If (B. Length = 2)
{
If (B [1] = 255)
{
B [0] = (byte) (B [0] + 32 );
B [1] = 0;
C [I] = system. Text. encoding. Unicode. getchars (B) [0];
}
}
}
String strnew = new string (C );
Function dbc2sbc (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 characters to the Unicode code of the corresponding half-width characters
} Else if (code = 12288) // Space
{
Result + = string. fromcharcode (Str. charcodeat (I)-12288 + 32 );
} Else
{
Result + = Str. charat (I );
}
}
Return result;
} In C. Directly use (INT) (char) to convert the data type.