c# - 如何从文本中找到最大出现的单词?

标签 c# asp.net linq

我有一个包含 string 值的数据库字段。 我正在寻找一种方法来从该字段中找到前 10 个出现次数最多的单词

最佳答案

首先获取该字段的所有单词:

IEnumerable<string> allWords = from entry in table
                               from word in entry.Field.Split(' ')
                               select word;

然后按数量对它们进行分组:

IEnumerable<string> result = from word in allWords
                             group word by word into grouped
                                 let count = grouped.Count()
                                 orderby count descending
                                 select grouped.Key;

获取前 10 个结果:

result.Take(10);

关于c# - 如何从文本中找到最大出现的单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7283185/

相关文章:

c# - Slapper & Dapper 词典支持

c# - LibUsbDotNet:退出 WPF 应用程序时出错 - 安全句柄已关闭

c# - 是否可以在预构建事件中更改文件的构建操作?

c# - 如何创建动态 'contains or LIKE' 表达式以与 Linq 针对 OData 服务一起使用

c# - 如何获取 IEnumerable 中元素的索引?

c# - 有没有办法在 .NET Core 中使用 Entity Framework?

ASP.NET 转发器分页/排序

c# - 将基类转换为派生类

c# - 如何为 Like 创建 System.Linq.Expressions.Expression?

javascript - 如何在AJAX错误方法中检索DbContext SqlException?