閱讀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 配置