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)); |
现在我想做两件我不知道该怎么做的事。
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"的列表。除此之外,您的代码还可以工作