Determines the number of Chinese characters in the input string and the number of Chinese characters in the string.
1 using System; 2 using System. collections. generic; 3 using System. componentModel; 4 using System. data; 5 using System. drawing; 6 using System. text; 7 using System. windows. forms; 8 using System. text. regularExpressions; 9 using System. collections; 10 11 namespace Test1912 {13 public partial class Form1: Form14 {15 public Form1 () 16 {17 InitializeComponent (); // initialize the Form 18} 19 private void button#click (ob Ject sender, EventArgs e) // click event 20 {21 ArrayList itemList = new ArrayList (); // defines an empty array 22 CharEnumerator CEnumerator = textBox1.Text. getEnumerator (); // give the string in textBox1 Text to CEnumerator23 Regex regex = new Regex ("^ [\ u4e00-\ u9fa5] {0,} $ "); // define a regular expression. Here, only Chinese characters can be entered. 24 while (CEnumerator. MoveNext () // incrementing index, pointing to the next character. If there is no next character, the loop is stopped. 25 {26 if (regex. isMatch (CEnumerator. current. toString (), 0) // if the current character of CEnumerator complies with the regex rule, insert this character into itemlist. 27 itemList. Add (CEnumerator. Current. ToString (); 28 textBox2.Text = itemList. Count. ToString (); // display the number of itemList items in textBox2. 29} 30} 31} 32}