Similar questions:
How to find substring in list of strings using LINQ
Find substring in a list of strings
Question:
I'm wondering if there's a method provided in C# .NET 4.5 which takes in a string and a delimiter as arguments and returns the element or index of element in a given List where the string is found delimited by the delimiter. Something like what Foo(string searchStr, char delimiter) does below?
Code:
List<string> list = new List<string>();
list.Add("XXX YYY ZZZ");
list.Add("AAA BBB CCC");
Console.WriteLine(list.Foo("XXX", ' ')); // should return 0 (index of element) or element of list
Console.WriteLine(list.Foo("YYY", ' ')); // should return -1 or null
Console.WriteLine(list.Foo("AAA", ' ')); // should return 1 (index of element) or element of list
Console.WriteLine(list.Foo("DDD", ' ')); // should return -1 or null