Find word which was the match
I have this code where I search a string for words from an array:
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));
Now I would like to achieve two things which I cannot figure out how to do.
true if found. i like my banjo then it should NOT find the letter a in banjo as the word a . It should only read a as a single word when it is in a sentence like this: i like a big beer at the end of the afternoon . Instead of any, use where:
var qa = pattern.Split(first_sentence).Where(w => wordlist.Contains(w));
Your wordlist should not be a string but a list or array of strings. Make sure it's a list that has "a" in it. Aside from that your code will work
链接地址: http://www.djcxy.com/p/75350.html上一篇: 我如何捕获var的结果
下一篇: 找到匹配的词
