I have a list:
var myList = new List<string> { "red", "blue", "green" };
I have a string:
var myString = "Alfred has a red and blue tie";
I am trying to get a count of matches of words in myList
within myString
. Currently, I am using .Contains()
, which gets me a count of 3 because it is picking up the "red" in "Alfred". I need to be able to osolate words instead. How can this be achieved?
var count = myList.Where(ml => myString.Contains(ml)); // gets 3, want 2