Find substring in a list of strings
.net, c#, linq, string, substring
Solution
With Linq, just retrieving the first result:
string result = list.FirstOrDefault(s => s.Contains(srch));
To do this w/o Linq (e.g. for earlier .NET version such as .NET 2.0) you can use `List<T>`'s `FindAll` method, which in this case would return all items in the list that contain the search term:
var resultList = list.FindAll(delegate(string s) { return s.Contains(srch); });
Problem
I have a list like so and I want to be able to search within this list for a substring coming from another string. Example: ``` List<string> list = new List<string>(); string srch = "There"; list.Add("1234 - Hello"); list.Add("4234 - There"); list.Add("2342 - World"); ``` I want to search for `"There"` within my list and return `"4234 - There"`. I've tried: ``` var mySearch = list.FindAll(S => s.substring(srch)); foreach(var temp in mySearch) { string result = temp; } ```