C# 正則表達式匹配漢字


int P_scalar = 0;
            Regex P_regex = new Regex("^[\u4E00-\u9FA5]{0,}$");
            for(int i = 0;i < txt_str.Text.Length; i++)
            {
                P_scalar = P_regex.IsMatch(txt_str.Text[i].ToString()) ? ++P_scalar : P_scalar;
            }
            MessageBox.Show(P_scalar.ToString(), "title");

 using System.Text.RegularExpressions;

"^[\u4E00-\u9FA5]{0,}$" 或者"^[\u4E00-\u9FA5]$"


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM