要阅读在文本框中输入一个字符串的所有字符没有重复,每个字符计数 [英] To read all characters from a string entered in text box without duplicates and count of each character
本文介绍了要阅读在文本框中输入一个字符串的所有字符没有重复,每个字符计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想每个字符的计数来读取文本框中输入一个字符串的所有字符重复没有,然后使用C#这些值存储到两格列,Asp.Net
例如:我的名字是乔
个字符Occurances
M 2 $ b $ 1 $ b $亿1
A 1 $ b $是2
I 1
S 1
J 1 $ b $波1
共计11
,然后将这些存储网格视图的列
解决方案
字符串输入=我的名字是乔;
VAR的结果=从C在input.ToCharArray()
,其中!Char.IsWhiteSpace(c)以Char.ToLower
组C(C)
为G
选择新的记录<字符串,整数>(g.Key.ToString(),g.Count());
INT总= result.Select(O => o.Item2).Aggregate((I,J)=> I + J);
名单,LT元组LT;字符串,整数>>元组= result.ToList();
tuples.Add(新的记录<字符串,整数>(合计,共));
和可以进行数据绑定的元组
列表DataGrid中:)
I want to read all characters from a string entered in a text box without repetitions with the count of each character and then store these values to two grid columns using C# ,Asp.Net
eg:My name is Joe
Characters Occurances M 2 y 1 n 1 a 1 e 2 i 1 s 1 j 1 o 1 Total 11
and then store these to the grid view columns
解决方案
string input = "My name is Joe";
var result = from c in input.ToCharArray()
where !Char.IsWhiteSpace(c)
group c by Char.ToLower(c)
into g
select new Tuple<string, int>(g.Key.ToString(),g.Count());
int total = result.Select(o => o.Item2).Aggregate((i, j) => i + j);
List<Tuple<string, int>> tuples = result.ToList();
tuples.Add(new Tuple<string, int>("Total", total));
And you can databind the tuples
list to the DataGrid :)
这篇关于要阅读在文本框中输入一个字符串的所有字符没有重复,每个字符计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文