阅读183 返回首页    go 阿里云 go 技术社区[云栖]


C#判断汉字的个数

  private void btnNum_Click(object sender, EventArgs e)
        {

            if (txtWords.Text.Length == 0)                      //判断是否为空
            {
                MessageBox.Show("请输入汉字:");        
                return;                                     
            }

            Regex reg = new Regex("^[\u4E00-\u9FA5]{0,}$");
            int iNumOfWords = 0;
            for (int i = 0; i < txtWords.Text.Length; i++)
            {
                iNumOfWords = reg.IsMatch(txtWords.Text[i].ToString()) ?
                    ++iNumOfWords : iNumOfWords;
            }
            txtNum.Text = Convert.ToString(iNumOfWords);
        }

最后更新:2017-04-02 00:06:51

  上一篇:go Linux时间函数之gettimeofday()函数之使用方法
  下一篇:go ubuntu 安装mysql 5.5.28 编译安装 innodb 配置