我有一个包含 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/