I have two lists:
var files = new List<string> {"ax_11118.txt", "ax_422226.txt", "ax_4346436.txt", "678678678.txt"};
var codes = new List<string> { "1111", "1234", "5555" };
I need to find the items in files which contain this format: "ax_code". The result in this case should be : { "ax_11118.txt" }
I know how to make it with foreach
, but I was thinking if there is a cleaner way.
If you want to check just code then:
files.Where(file => codes.Any(file.Contains));
if ax_code:
files.Where(file => codes.Any(code => file.Contains($"ax_{code}")));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments