现在我正在做这样的事情来删除myList中的单词,这是正常的,
List<string> myList = matches
.Cast<Match>()
.Select(m => m.Value)
.Distinct()
.ToList();
myList.RemoveAll((x) => x.Contains("word1")
|| x.Contains("word1")
|| x.Contains("word2")
|| x.Contains("word3")
|| x.StartsWith("D")
);
string[] ab = new string[] { "word1", "word2", "word3" };
Run Code Online (Sandbox Code Playgroud)
但现在我想提供一个字符串[]列表而不是添加x.Contains("blah blah")其次我还想将两个语句合并为一个,使其成为单个linq查询.
Enumerable.Except是您过滤掉项目的朋友.你需要做一个决赛Where
来处理这个StartsWith
案子.
IEnumerable<string> filtered = myList.Except(ab);
Run Code Online (Sandbox Code Playgroud)
所以完整:
IEnumerable<string> myList = matches.Select(_ => _.Value)
.Distinct()
.Except(new [] { "word1", "word2", "word3" })
.Where(_ => !_.StartsWith("D"));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3149 次 |
最近记录: |