Reputation: 3291
I have a list string:
List<string> Entries = new List<string>();
Entries.Add("The quick brown fox jumps over the lazy dog");
Entries.Add("Lorem ipsum dolor sit amet");
Entires.Add("Consetetur sadipscing elitr");
Can I search for something like "fox"
in the list and get the whole line ("The quick brown fox jumps over the lazy dog"
) returned?
Upvotes: 0
Views: 1617
Reputation: 26209
Step 1: You can iterate over Entries
using foreach
loop.
Step 2: invoke Contains()
method on every loop item to check required string (fox)
.
foreach (var item in Entries)
{
if (item.Contains("fox"))
Console.WriteLine(item); //item found
}
Upvotes: 2