I have tried two different way to search this string and match it to the Appendixkeywords string. I have tried using Array.Exists and Array.IndexOf but both are not finding the Appendixkeywords. Any help would be great.
working sample
https://dotnetfiddle.net/QIXFDn
>Solution :
I assume you want to check whether your source string contains any of the strings specified in your Appendixkeywords array. Additionally I assume you want to achieve a case insensitive comparison.
bool foundAnyAppendixWord = Appendixkeywords
.Any(word => source
.Contains(word, StringComparison.InvariantCultureIgnoreCase));
You could (and maybe even should) turn this easily into a reusable method
static bool ContainsAnySearchWord(string[] searchWords, string target)
{
return searchWords.Any(word => target
.Contains(word, StringComparison.InvariantCultureIgnoreCase));
}
// ...
bool foundAnyAppendixWord = ContainsAnySearchWord(Appendixkeywords, source);
.NET Framework (and older) versions:
static bool ContainsAnySearchWord(string[] searchWords, string target)
{
return searchWords.Any(word => target.ToLower()
.Contains(word.ToLower()));
}
Edit
You also have to add a using System.Linq; 🙂