how to search string str = "three"; in list List = new List<string> { "line one", "line two", "line three", "line four", "row three", "linethree", "three" }; to get this result:
line three
row three
three
Split each string with space and check if any splited string equals to your target string. Here is the code:
var list = new List<string> { "line one", "line two", "line three", "line four", "row three", "linethree", "three" };
var result = list.Where(i => i.Split(' ').Any(j => j.Equals("three"))).ToList();
//result:
// line three
// row three
// three
Also you may want to use StringComparison.InvariantCultureIgnoreCase as the second parameter of the Equals method in the case that you are looking for case-insensitive solution.
add space at the first of three like this:
string str = " three"
so it just get words
and for updated input use like this
string str = " "+"three"