Bit different solution.
void Main()
{
var KeyWords = new List<string>(){ "Test","Re Test","ACK" };
var array = new string[] {
"Please give the Test",
"Please give Re Test",
"Acknowledge my work"
};
foreach(var c in array)
{
Contains(c,KeyWords); // Your result.
}
}
private bool Contains(string sentence, List<string> keywords) {
var result = keywords.Select(keyWord=>{
var parts3 = Regex.Split(sentence, keyWord, RegexOptions.IgnoreCase).Where(x=>!string.IsNullOrWhiteSpace(x)).First().Split((char[])null); // Split by the keywords and get the rest of the words splitted by empty space
var splitted = sentence.Split((char[])null); // split the original string.
return parts3.Where(t=>!string.IsNullOrWhiteSpace(t)).All(x=>splitted.Any(t=>t.Trim().Equals(x.Trim(),StringComparison.InvariantCultureIgnoreCase)));
}); // Check if all remaining words from parts3 are inside the existing splitted string, thus verifying if full words.
return result.All(x=>x);// if everything matches then it was a match on full word.
}
The Idea is to split by the word you are looking for e.g Split by ACK
and then see if the remaining words are matched by words splitted inside the original string, if the remaining match that means there was a word match and thus a true. If it is a part split meaning a sub string was taken out, then words wont match and thus result will be false.