Home > DeveloperSection > Forums > Result of LINQ.Any to string
Garry Winogrand
Garry Winogrand

Total Post:24

Points:168
Posted on    October-05-2013 9:09 AM

 C# C# 
Ratings:


 1 Reply(s)
 752  View(s)
Rate this:

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.



Dag Hammarskjold
Dag Hammarskjold

Total Post:24

Points:168
Posted on    October-05-2013 9:29 AM

var match = stringArray.FirstOrDefault(s => stringToCheck.Contains(s));
if(match != null) {
    // match was found
}

Don't want to miss updates? Please click the below button!

Follow MindStick