日期:2014-05-18  浏览次数:20880 次

字符串查找问题求聪明解法
打比方说就是求string   s   =   "adAwSD?asd   fds   a45a3sd?sad23   fwds ";这个字符串中:?号,空格,数字,字母(不分大小写)的个数????????

------解决方案--------------------
如果只是统计数字和字母的个数很容易

int dCount = 0; //数字
int cCount = 0; //字母
string s = "adAwSD?asd fds a45a3sd?sad23 fwds ";
foreach (char c in s)
{
if (c > = '0 ' && c <= '9 ')
dCount++;
else if (char.ToLower(c) > = 'a ' && char.ToLower(c) <= 'z ')
cCount++;
}

如果统计其它的,那就看你的规则了,是单独统计,还是说除这两种字符之外,放在一起统计