I\'m reading a comma-delimited list of strings from a config file. I need to check whether another string is in that list. For example:
\"apple,banana,cheese\"
Here's an option that ignores case.
var food = "apple,banana,cheese";
bool containsApp = food.Split(',')
.Where(s => string.Compare("app", s, true) == 0)
.Count() > 0;
bool containsApple = food.Split(',')
.Where(s => string.Compare("apple", s, true) == 0)
.Count() > 0;
Console.WriteLine("Contains \"app\"? {0}", containsApp);
Console.WriteLine("Contains \"apple\"? {0}", containsApple);