So, I check if a string contains a certain word from an array with the following statement:
if(stringArray.Any(s => stringToCheck.Contains(s)))
Simple. Now a match is found and the statement is true. But I want to know also which item in the array matched with the string. The placeholder "s" in the LINQ statement above is not available in the following clause.
Hope somebody has an idea. I could just loop through the array, yes, but LINQ looks way nicer to me. =)
var match = stringArray.FirstOrDefault(s => stringToCheck.Contains(s));
if(match != null) {
// match was found
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With