62,241
社区成员




var query = Key.Split(',').GroupBy(x => x).Select(x => new { key = x.Key, nums = x.Sum(p => p.Count()) }).Take(10).OrderByDescending(x => x.nums);
现在,我想先对Key中分割的字符串按长度排序,然后分组查处出现频率高的10个字符串怎么写呢?
再次感谢~[/quote]
加一个OrderBy(x => x.Length)
var query = Key.Split(',').GroupBy(x => x).Select(x => new { key = x.Key, nums = x.Sum(p => p.Count()) }).Take(10).OrderByDescending(x => x.nums);
现在,我想先对Key中分割的字符串按长度排序,然后分组查处出现频率高的10个字符串怎么写呢?
再次感谢~
var query = "中国,河南,合肥,中国,中国人,河南,字符串,字符串,字符串,字符串,中国人".Split(',').GroupBy(x => x).Select(x => new { key = x.Key, nums = x.Sum(p => p.Count()) }).Take(3);
foreach (var item in query)
{
Console.WriteLine("字符串:"+item.key+" 次数:"+item.nums);
}
Console.Read();
string key = "中国,河南,合肥,中国,中国人,河南,字符串,字符串,字符串,字符串,中国人";
var list = Regex.Split(key, @"[,,]", RegexOptions.IgnorePatternWhitespace).GroupBy(a => a).OrderByDescending(a => a.Count()).Select(a =>a.Key).Take(3).ToList();
/*
[0] "字符串" string
[1] "中国" string
[2] "河南" string
*/