国产探花免费观看_亚洲丰满少妇自慰呻吟_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 }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 曲阜市| 新兴县| 木兰县| 托克逊县| 望城县| 宁远县| 江门市| 绩溪县| 桃园市| 水城县| 德化县| 定襄县| 罗定市| 乐至县| 阳曲县| 江源县| 建宁县| 惠来县| 那曲县| 阿合奇县| 于都县| 兰西县| 馆陶县| 赞皇县| 邯郸市| 乐业县| 和平县| 铜鼓县| 大城县| 宁明县| 武定县| 安远县| 靖远县| 丹江口市| 嘉荫县| 阳朔县| 文成县| 淳安县| 建始县| 南岸区| 金门县|