关于c#:查找匹配的单词

Find word which was the match

我有这样的代码,我在其中搜索数组中的单词字符串:

1
2
3
4
5
string wordlist = synonymslistbox.Items[q_index].ToString().Split(':')[0].Replace(',', ' ');

var pattern = new Regex(@"\W");

var qa = pattern.Split(first_sentence).Any(w => wordlist.Contains(w));

现在我想做两件我不知道该怎么做的事。

  • 找出哪个词是匹配词。如果找到,此代码只返回true
  • 当第一句话是i like my banjo时,它不应该在banjo中找到字母a作为单词a的位置。只有在这样的句子中,它才应该把a作为一个单独的单词来读:i like a big beer at the end of the afternoon

  • find out witch word was a match. this one just returns true if found.
  • 在以下情况下使用,而不是任何:

    1
    var qa = pattern.Split(first_sentence).Where(w => wordlist.Contains(w));
  • when first_sentences is"i like my banjo" then it should NOT find a in banjo as the word a. it should only read a as a single word when
    it is in a sentence like this below"i like a big beer at the end of
    the afternoon"
  • 单词表不应是字符串,而应是字符串列表或数组。确保它是一个包含"a"的列表。除此之外,您的代码还可以工作