LINQ - Check if the array contains a certain keyword

I have a dictionary of array of string.

Example:
Arr = {“#123 ABCDE XXX, “#567 Apple YYY”, “#889 Orange ZZZ”}
I need to check if the array contains a certain keyword(like as Apple).
And get the item in array.

Thanks!

try this

arr.Where(Function(s) s.Contains(keyword)).ToArray()
1 Like

@rockchord

Arr = New Dictionary(Of String, String) From {
    {"item1", "#123 ABCDE XXX"},
    {"item2", "#567 Apple YYY"},
    {"item3", "#889 Orange ZZZ"}
}
matchedItems = Arr.Where(Function(kvp) kvp.Value.Contains("Apple")).Select(Function(kvp) kvp.Value).ToList()

1 Like

That works! Thank you!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.