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.

  • Find out which word was a match. This code just returns true if found.
  • When first_sentences is 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 .

  • find out witch word was a match. this one just returns true if found.
  • Instead of any, use where:

    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"
  • 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的结果

    下一篇: 找到匹配的词