I have declared following List of strings-
List lstfruits= new List(){
{ "apple-2015.05.18.html" },{ "apple-1997.01.11.html" },{ "mango-2013.02.12.html" },{ "peach-2015.04.12.html" },{ "peach-1998.11.12.html" },{ "other-2013.02.12.html" },
};
I need to match all records which contain 'apple'. Below are the results that I want-
"apple-2015.05.18.html"
"apple-1997.01.11.html"
I wrote below , but it returns zero results-
var items = lstfruits.Where(pp => pp.Substring(0, pp.IndexOf('-')) == "apple");
Please help where I am wrong.

Saroj Kumar SahuRank #1,766 · 849 reputationPosted Jun 16, 2015, 9:17 PM EDT
Sreekanth ReddyRank #726 · 3.2K reputationPosted Jun 16, 2015, 9:01 PM EDT
Saroj Kumar SahuRank #1,766 · 849 reputationPosted Jun 16, 2015, 9:03 PM EDT
T K25 reputationPosted Jun 16, 2015, 9:04 PM EDT
Bhushan BhasmeRank #2,348 · 604 reputationPosted Jun 16, 2015, 9:08 PM EDT
List
{ "apple-2015.05.18.html" },
{ "apple123-1997.01.11.html" },
{ "apple-1997.01.11.html" },
{ "mango-2013.02.12.html" },
{ "peach-2015.04.12.html" },
{ "peach-1998.11.12.html" },
{ "other-2013.02.12.html" },
};
string a = "apple";
lstfruits = lstfruits.Where(m => m.Contains(a)).ToList();
foreach (var item in lstfruits)
{
if (item.Split('-')[0].Length == a.Length)
{
lstfruitName.Add(item);
}
}
lstfruits = lstfruits.Where(m => m.Contains(a)).ToList();
foreach (var item in lstfruits)
{
if(item.Substring(0,item.IndexOf('-'))=="apple")
{
lstfruitName.Add(item);
}
}
}
Hope This Will Help You
Sreekanth ReddyRank #726 · 3.2K reputationPosted Jun 16, 2015, 9:12 PM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 16, 2015, 10:37 PM EDT
T K25 reputationPosted Jun 17, 2015, 12:44 AM EDT