Judgment of Chinese characters

xiaoxiao2021-03-06  21

In UNCIDE: CHAR [] OSOUR = this.TextBox1.text.tochararray (); int os = communication.toint32 (OSOUR [i]); if (OS> = 19968 && OS <= 40869) {// is Chinese characters} Else {// Non-Chinese characters}

Chinese character processing function set, the bottom layer function, based on GB18030

Judging the number of bytes of the first character. The return value is less than 2, indicating that the first character is not Chinese. / ************************************************** *********************************************** Function: GetCharsize Description: this function return the size of listed character of specified data string. Input: 1 String size return: -1. invalid character 0. Null string> 0. character size ********************************** *********************************************************** **** / int GETCHARSIZE (const char * data, int size) {const unsigned char * p = (unsigned char *) data; // check arguments if (p == null || size <= 0) returnograph; // Chinese 1st Byte 0x81-0xfe if (p [0] <0x81 || P [0]> 0xfe) Return 1; // Chinese code size = 2, 4 IF (SIZE <2) Return-1; // Chinese 2nd Byte 0x30-0X39, 0x40-0X7E, 0x80-0XFE IF (P [1] <0x30 || P [1]> 0x39 && P [1] <0x40 || P [1] == 0x7f || P [1 ]> 0xfe) Return -1; // 2 Bytes Chinese Code if (p [1]> = 0x40) Return 2; // Chinese c Ode size = 4 IF (SIZE <4) Return -1; // Chinese 3rd Byte 0x81-0XFE IF (P [2] <0x81 || P [2]> 0xfe) Return -1; // Chinese 4th Byte 0x30- 0x39 IF (P [3] <0x30 || P [3]> 0x39) Return -1; Return 4;} Judgment whether Chinese characters: #define ischinese (x, y) (getcharsize (x, y)> 1) Find characters Invalid characters in the string (incomplete Chinese characters) returns a pointer or empty point to the character.

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

New Post(0)