Jeremy Stein Jeremy Stein - 2 months ago 6x
C# Question

Best way to check for string in comma-delimited list with .NET?

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:


If I check for
I should find it, but if I check for
I should not.

What's the most straight-forward and concise way to do this? It doesn't have to be fast.

(I'll add my solution as an answer, but I'm hoping someone has something better.)


Using linq:


W/o linq:

Array.IndexOf(listString.Split(','), "apple") >= 0