Chinese character zone code query

xiaoxiao2021-03-06  15

Recently, a buddy invited me to help them in the entire location code query. Get it, put it here, please use the buddy reference. If you have any place, please pay more attention.

principle:

The zone code algorithm of Chinese characters:

((The first byte of Chinese characters - 0xA1) * 94 (the second byte of Chinese characters - 0xa1) * 32

Area code = Chinese characters machine code high byte -a0

Bitt code = low byte of the machine code of Chinese characters - A0

Is the Chinese character text file read out the Chinese characters (can be implemented with C language or VB), two bytes

Representing a word machine, high in front, low in the low

If the location code of "ah" is 1601, the machine is B

0A

1 (16)

C # version

Public String TextToqWM (String Character)

{

String Coding = "";

INT I1 = 0, I2 = 0, i3 = 0;

For (int i = 0; i

{

Byte [] bytes = system.text.Encoding.default.getbytes (Character.Substring (i, 1)); // Remove the binary coding content

I1 = (Short); Bytes [0]);

Try

{

I2 = (Short); Bytes [1]);

i3 = 1;

}

Catch (Exception EX)

{

I2 = 65536; i3 = -1;

}

Finally

{

INTCHRASC = I1 * 256 i2-65536;

IF (Chrasc> 0 && Chrasc <160)

{

TextBox2.text = "You can only enter Chinese characters !!";

}

Else

{

IF (i3 == - 1)

{

TextBox2.text = "You can only enter Chinese characters !!";

}

Else

{

String lowcode = system.convert.tostring (Math.Toint 32 (System.TOINT32 (Bytes [0])) - 160)); // Remove the low-byte coding content (two-digit 16)

IF (lowcode.length == 1)

Lowcode = "0" lowcode;

String hightcode = system.convert.tostring (Math.Toint 32 (System.TOINT32 (Bytes [1])) - 160)); // Remove high byte coding content (two-digit 16)

IF (hightcode.length == 1)

Hightcode = "0" hightcode;

Coding = character.substring (i, 1) (Lowcode Hightcode); //

Add to the string,

}

}

}

}

Return Coding;

}

VBScript version

转载请注明原文地址:https://www.9cbs.com/read-45819.html

New Post(0)