LINQ可以用来从字符串中提取关键字吗?

Cha*_*eus 4 c# linq string

如果我有一个长文本字符串并且想要提取长度大于4个字符且在字符串中发现超过4次的单词,LINQ可以这样做吗?

Ant*_*ram 15

你可能能够收紧这个,但我相信它会产生影响

var results = inputstring.Split()
                .Where(word => word.Length > 4)
                .GroupBy(word => word)
                .Where(grp => grp.Count() > 4)
                .Select(grp => grp.Key);
Run Code Online (Sandbox Code Playgroud)

当然,您需要决定如何处理可能存在的标点符号.

所以给出了输入

var inputstring = @"The quick brown fox jumped over the lazy dog 
               The quick brown fox jumped over the lazy dog 
               The quick fox jumped over the lazy dog 
               The quick fox jumped over the lazy dog 
               The quick brown fox jumped over the lazy dog";
Run Code Online (Sandbox Code Playgroud)

结果包含"快速"和"跳跃",因为大于4个字符("棕色")的唯一其他单词仅出现3次.