计算每个字符出现的次数(两种方法)
来源:互联网 发布:福彩3d开奖数据下载 编辑:程序博客网 时间:2024/05/18 02:39
#region Dictionary 计算每个字符出现的次数
//string str = "Welcome to Chinaworld";
//str = str.ToUpper();
//Dictionary<char, int> dic = new Dictionary<char, int>();
//for (int i = 0; i < str.Length; i++)
//{
// if (char.IsLetter(str[i]) == true)
// {
// if (dic.Keys.Contains(str[i]))
// {
// dic[str[i]]++;
// }
// else
// {
// dic[str[i]] = 1;
// }
// }
//}
//foreach (KeyValuePair<char, int> item in dic)
//{
// Console.WriteLine("{0}{1}", item.Key, item.Value);
//}
#endregion
#region Hashtable 计算每个字符出现的次数
int numb1;
string str = "Welcome to Chinaworld";
str = str.ToUpper();
Hashtable table = new Hashtable();
for (int i = 0; i < str.Length; i++)
{
if (char.IsLetter(str[i]) == true)
{
if (table.ContainsKey(str[i]))
{
numb1 = Convert.ToInt32(table[str[i]]);
numb1++;
table[str[i]] = numb1;
}
else
{
numb1 = Convert.ToInt32(table[str[i]]);
numb1=1;
table[str[i]] = numb1;
}
}
}
foreach (DictionaryEntry item in table)
{
Console.WriteLine("{0}{1}", item.Key, item.Value);
}
#endregion
- 计算每个字符出现的次数(两种方法)
- 计算一个字符串中每个字符出现的次数
- 计算字符串中每个字符出现的次数
- C# 计算字符串中每个字符出现的次数
- 每个字符出现的次数
- 计算字符出现的次数
- 统计字符串每个字符出现的次数
- String中每个字符出现的次数
- C#统计每个字符出现的次数
- 统计每个字符出现的次数
- Counter统计每个字符出现的次数
- 统计每个ASCII字符出现的次数
- php如何计算一个字符串的每个字符出现的次数
- 小方法1——CountChar--统计一个字符串中每个字符出现的次数
- 计算字符串中出现字符的次数
- 计算字符串中出现字符的次数
- 计算大小字符分别出现的次数
- (74)TreeMap练习:求字符串中每个字符出现的次数(键值对:字符---次数)
- 测试驱动开发 Test-driven development
- C#运算符优先级
- 50 Tips for Working with Unity (Best Practices)
- Linux C++ 获取磁盘 大小 格式 信息
- MySQL Duplicate entry 问题备注
- 计算每个字符出现的次数(两种方法)
- C++笔记:Const
- VPS中使用XAMPP MySQL无法启动原因及解决办法
- 35+ 个免费下载的 HTML5/CSS3 下拉菜单(附下载地址)
- 感兴趣区域ROI 和 替换算法
- 端口Access、Hybrid和Trunk三种模式的理解
- 管理新手的无知呓语——leo鉴书49
- sql去空格
- usaco training 5.3.4 Big Barn 题解