我有一个要过滤的目录中的文件列表。文件名如下:
FileBanana.txt
FileMango.txt
FileBananaShake.txt
FileOrange.txt
FileGrapes.txt
FileOrangeJuice.txt
FileNactarine.txt
我想获得一个字符串列表,其中的文件包含另一个列表中的任何项目{" Orange"," Banana"}
如何使用LINQ做到这一点?
答案 0 :(得分:0)
也许我只是困惑自己。这很好用:
List<string> stringFiles = new List<string>() {"FileBanana.txt", "FileMango.txt", "FileBananaShake.txt", "FileOrange.txt", "FileGrapes.txt", "FileOrangeJuice.txt", "FileGrapes.txt" };
List<string> filterKeywords = new List<string>() { "Orange", "Banana" };
var result = from p in stringFiles
where filterKeywords.Any(val => p.Contains(val))
select p;