拆分标题并计算拆分后的单词在c#net的相应段落中出现的次数

拆分标题并计算拆分后的单词在c#net的相应段落中出现的次数,c#,arrays,string,for-loop,c#-4.0,C#,Arrays,String,For Loop,C# 4.0,我有这样的要求。 一页中有两件事可用,即。 文章标题和内容 发布内容段落。 首先,将文章标题句子分成几个单词,然后计算单词在相应文章内容段落中出现的次数。C#.net中的适当逻辑应该是什么?用于拆分文本: string[] words = postTitle.Split(' '); 然后使用以下方法查找帖子内容中的每个字数: public static int CountWords(string s) { MatchCollection collection = Re

我有这样的要求。 一页中有两件事可用,即。 文章标题和内容 发布内容段落。
首先,将文章标题句子分成几个单词,然后计算单词在相应文章内容段落中出现的次数。C#.net中的适当逻辑应该是什么?

用于拆分文本:

         string[] words = postTitle.Split(' ');
然后使用以下方法查找帖子内容中的每个字数:

public static int CountWords(string s)
{
    MatchCollection collection = Regex.Matches(s, @"[\S]+");
    return collection.Count;
}

你可以试试他的:

string postTitle = "This is Title";
string postContent = "This will be the content corresponds to the above title, this will be updated later";
string[] contentWords = postContent.Split(' ');
var wordsNcount = String.Join("\n", postTitle.Split(' ').Select(x => x + " : " + contentWords.Count(y => y == x).ToString()));

这将是区分大小写的比较,您可以参考,其中我也包含了不区分大小写的比较。

您的标记回答您的
什么是适当的逻辑问题。你试过什么吗?显示您的代码。