国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

判斷輸入字符中包含漢字數目

2019-11-14 13:51:44
字體:
來源:轉載
供稿:網友
 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();//初始化窗體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 }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东安县| 左贡县| 华亭县| 偃师市| 满洲里市| 长顺县| 三江| 基隆市| 桑植县| 长岛县| 布尔津县| 丰城市| 日土县| 乌海市| 湘阴县| 南华县| 万荣县| 济阳县| 饶河县| 长岛县| 科技| 太保市| 得荣县| 南乐县| 松江区| 安吉县| 洛扎县| 梨树县| 旺苍县| 清苑县| 进贤县| 长乐市| 龙川县| 文山县| 平利县| 陆良县| 河南省| 琼结县| 天水市| 大新县| 汝城县|