This article through the example code to introduce the use of C # Regular expression validation of Chinese characters method, the need for a friend to refer to the bar
Not much nonsense to say, directly to everyone to paste the code, the specific code is as follows:
Using system;using system.collections.generic;using system.linq;using system.text;using System.text.regularexpressions;using system.threading.tasks;namespace Regular Expression 01{///<summary>//Whether the character is Chinese// /</summary> Class Program {///<summary>///In the ASCII code table, the English range is 0-127, while kanji is greater than 127//</SUMMARY&G T static void Justice1 () {String text = "Adonai, the world hero out of the My generation, one into the lakes and rivers of the years urged." Hung figure BR laugh, life a drunk. The Sword Cross Rides The Ghost rain, the skeleton like the mountain bird startled flies. Earthly like water, only sigh a few people back "; for (int i = 0; i < text. Length; i++) {if ((int) text[i] > 127) Console.WriteLine ("is Kanji"); else Console.WriteLine ("Not kanji"); }}///<summary>///Kanji Unicode encoding range is 4E00-9FBB//</summary> static void Justice2 () {str ing text = "Adonai, the world hero out of my generation, one into the lakes and rivers of the years urged." Hung figure BR laugh, life a drunk. The Sword Cross Rides The Ghost rain, the skeleton like the mountain bird startled flies. Earthly like water, only sigh a few people back "; Char[] C = text. ToCharArray (); for (int i = 0; i < c.length; i++) if (C[i] >= 0x4e00 && c[i] <= 0x9fbb) console.writeLine ("is kanji"); else Console.WriteLine ("Not kanji"); }///<summary>///Regular expressions are judged by the UNICODE encoding range of Chinese characters///</summary> static void Justice3 () {string Text = "Adonai, the world hero out of my generation, one into the lakes and rivers of the years urged." Hung figure BR laugh, life a drunk. The Sword Cross Rides The Ghost rain, the skeleton like the mountain bird startled flies. Earthly like water, only sigh a few people back "; for (int i = 0; i < text. Length; i++) {if (Regex.IsMatch (Text[i]). ToString (), @ "[\U4E00-\U9FBB]")) Console.WriteLine ("is Kanji"); else Console.WriteLine ("Not kanji"); }} static void Main (string[] args) {Justice1 (); Console.readkey (); } }}