你的位置:首页 > 软件开发 > ASP.net > 判断输入字符中包含汉字数目

判断输入字符中包含汉字数目

发布时间:2015-10-27 22:00:24
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using Syst ...

判断输入字符中包含汉字数目

 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Draget='_blank'>wing; 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();//初始化窗体18     }19     private void button1_Click(object sender, EventArgs e)//button1的单击事件20     {21       ArrayList itemList = new ArrayList();//定义一个空数组22       CharEnumerator CEnumerator = textBox1.Text.GetEnumerator();//将textBox1的Text中的字符串给CEnumerator23       Regex regex = new Regex("^[\u4e00-\u9fa5]{0,}$");//定义一个正则表达式,这里是只允许输入汉字的意思。24       while (CEnumerator.MoveNext())//递增索引,指向下一个字符,如果没有下一个就停止循环。25       {26         if (regex.IsMatch(CEnumerator.Current.ToString(), 0))//如果CEnumerator的当前字符符合regex这个规则,那么就把这个字符插入到itemlist里面。27           itemList.Add(CEnumerator.Current.ToString());28         textBox2.Text = itemList.Count.ToString();//将itemList的项数显示到textBox2里面。29       }30     }31   }32 }

原标题:判断输入字符中包含汉字数目

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录