I have a list of string and gridview rows where I need to find if row contains any of the string from my list and return the matched string.
This is my list sample:
List<string> lstFind = new List<string>() { "TXT1", "TXT2", "TXT3", "TXT4" };
Then I need to check if row contains any of the string from my list above, something like...
lstRemovecol.Any(row["Item code"].ToString()
How do I accomplish that?
Thank you in advance.
If you're looking for an exact match, you just need:
bool found = lstRemovecol.Contains(row["Item code"].ToString());
No need for LINQ at all, or Any
.
If you're trying to find any of the items within a longer string (for example, if the entry was "This is TXT1 that you should find", you'd want something like:
string code = row["Item code"].ToString(); // Or use a cast
bool found = lstRemovecol.Any(item => code.Contains(item));
See more on this question at Stackoverflow