How regular expressions in C # Validate instances of Chinese characters

Source: Internet
Author: User
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//&LT;/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 (); }  }}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.