字符串查找问题求聪明解法 打比方说就是求string s = "adAwSD?asd fds a45a3sd?sad23 fwds";这个字符串中:?号,空格,数字,字母(不分大小写)的个数???????? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 怎么求一个数字在字符串中出现的个数,仿佛可以通过字母的ASC11码来做,具体怎么做,现在在网上搜不找了 如果只是统计数字和字母的个数很容易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++;}如果统计其它的,那就看你的规则了,是单独统计,还是说除这两种字符之外,放在一起统计 谢谢lxcnn(过客)的指点空格 和 符号 要怎么办啊? 单独统计就在后面加if分支就行了,比如统计空格int dCount = 0;int cCount = 0;int spaceCount = 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++; else if (c == ' ') spaceCount++;} 如何在datagridview的单元格右上方显示一个小图片 是用C#写WEBFORM就叫ASP吗?我怎么觉得ASP和C#是完全不同的两回事啊? VS2005 GridView 模版列问题? 高手请`` System.Web.HttpContext.Current.User.Identity进行用户安全信息认证的问题 DOS命令问题 实现了一个俄罗斯方块 做过VOD系统需要些什么技术实现?一百分 怎样设置才能回到从前 有关论坛显示的问题? 非按键相应事件中 如何判断按键值 救命啊 请高手帮我看看为什么我在相对路径上无法读到文件 这个字符串怎么操作?
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++;
}如果统计其它的,那就看你的规则了,是单独统计,还是说除这两种字符之外,放在一起统计
int cCount = 0;
int spaceCount = 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++;
else if (c == ' ')
spaceCount++;
}