zoukankan      html  css  js  c++  java
  • 判断输入字符中包含汉字数目

     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 Test19
    12 {
    13     public partial class Form1 : Form
    14     {
    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中的字符串给CEnumerator
    23             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 }

  • 相关阅读:
    外部排序
    oceanbase tpcc 关键总结
    TPCC测试
    最简单的oracle 19c安装教程
    unix进程环境
    tars以docker方式安装
    异常安全的赋值运算符函数
    linux 定时器setitimer使用
    libevent学习-reactor设计模式及代码示例
    linux中可执行程序搜索动态链接库的顺序
  • 原文地址:https://www.cnblogs.com/liuyaozhi/p/4915629.html
Copyright © 2011-2022 走看看