namespace 作业1
{
class Program
{
private static object ToUpper;
static void Main(string[] args)
{
string str = "Hello,Welcome to WuHan,wwwkjdsldjfifnkldsijf!!!!";
Dictionary dic = new Dictionary();
for (int i = 0; i < str.Length; i++)
{
if (char.IsLetter(str[i]))
{
if (dic.ContainsKey(str[i]))
{
dic[str[i]]++;
}
else
{
** str[i]=ToUpper(str[i]);这样为什么不行
if (dic.ContainsKey(str[i]))
{
dic[str[i]]++;
} **
else{
dic.Add(str[i], 1);
}
}
}
}
}
还有
for (int i = 0; i < str.Length; i++)
{
if (char.IsLetter(str[i]))
{
if (dic.ContainsKey( * str[i])=ToUpper(str[i])) *
{
dic[str[i]]++;
}
else
{
dic.Add(str[i], 1);
}
}
筛选字符串中的字母且不区分大小写,以第一个遇到的形式输出
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
feiyun0112 2014-11-06 01:49关注插入的key要大写
dic.Add(ToUpper(str[i]), 1);本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报