c# - 如何使用 C# 或 jquery 匹配段落中的重复单词?

标签 c# jquery

我想匹配两个字符串之间的常用词

// C# code  
string str1,str2;

我想检查字符串str1的前十五个单词中的五个单词

str1="Musician Ben Sollee on the Ravages of Coal and the Wonders of the Bicycle"
str2="There is Wonders of Musician Ben Sollee on the Ravages of Coal"

我想跳过“of”、“on”、“the”等以上字符串的动词比较。只检查没有动词的单词...

从上面的字符串我想比较 str2str1 如果它包含五个重复的单词然后给出消息它包含一些重复的单词..

我如何比较它并检查它是否包含重复项。我对 jQuery 或 C# 答案很满意。

最佳答案

奖励积分的单行 Linq 查询?

string[] str1Words = ...
string[] str2Words = ...
string[] dontCheck = {"of", "a", "the"};

var greaterThanFive = str1Words.Join(str2Words, s1 => s1, s2 => s2, (r1, r2) => r1)
                               .Distinct()
                               .Where(s => !dontCheck.Contains(s))
                               .Count() > 5;

关于c# - 如何使用 C# 或 jquery 匹配段落中的重复单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6420669/

相关文章:

java - 如何每 500 - 1000 毫秒刷新一次 div 标签?

c# - 在不应该为 DataTable 抛出 RowNotInTableException 时?

c# - 自托管 WCF 和 SSL(再次)

c# - Sparx EA .feap 项目图像保存为空白

jquery - 如何为具有 Jquery 的 aspx 页面中的列表实现 "bring to front"

javascript - 如何使用条件运算符分配ID?

c# - 返回时导致 SEGFAULT 的非托管函数指针

c# - 我应该如何组合两条路径,包括向后相对路径?

javascript - 如果 href 为空则隐藏链接,然后显示不同的按钮?

php - AJAX 够用吗?我应该学习 PHP 框架吗?