There are three ways to determine if a character is a kanji:
[1] The ASCII code is judged, [2] is judged by the UNICODE encoding range of the Chinese character, [3] is judged by the regular expression.
1. Use ASCII code to judge
In the ASCII code table, the English range is 0-127, while the kanji is greater than 127, the specific code is as follows:
stringText ="Kanji, ABC"; for(inti =0; I < text. Length; i++) { if((int) Text[i] >127) Console.WriteLine ("It's kanji ."); ElseConsole.WriteLine ("not kanji ."); }
2, using the UNICODE encoding range of Chinese characters to judge
The UNICODE encoding range of Chinese characters is 4e00-9fbb, the specific code is as follows:
stringText ="Kanji, ABC"; Char[] C =text. ToCharArray (); for(inti =0; I < c.length;i++){ if(C[i] >=0x4e00&& C[i] <=0X9FBB) Console.WriteLine ("It's kanji ."); ElseConsole.WriteLine ("not kanji .");
}
3. Judging with regular expression
The regular expression is also used to determine the UNICODE encoding range of Chinese characters, the specific code is as follows:
string text = " Kanji, ABC " for (int i = 0 ; i < text. Length; I++ if (Regex.IsMatch (text[i). ToString (), @ " [\u4e00-\u9fbb]+{1}quot;)) Console.WriteLine ( is a Chinese character " else Console.WriteLine ( " not kanji "
C # To determine whether a character is a kanji