using System.Text.RegularExpressions;
private string GetResult(string str)
{
int len=str.Length;
str=Regex.Replace(str,"[a-zA-Z]","");
string result=(len-str.Length)+"个字母 ";
len=str.Length;
str=Regex.Replace(str,"[0-9]","");
result+=(len-str.Length)+"个数字 ";
len=str.Length;
str=Regex.Replace(str,"[\u4e00-\u9fa5]","");
result+=(len-str.Length)+"个中文";
return result;
}
本文介绍了一种使用正则表达式统计字符串中字母、数字及中文字符数量的方法。通过C#实现,逐一对字符串中的各类字符进行过滤并计算数量。
869

被折叠的 条评论
为什么被折叠?



