Linq搜索字符串单词分隔字符串
我有一张绳子的清单。我想在里面搜索并返回一个新列表。搜索值是一个字符串(句子)。每个单词都被一个空格分开 因此,我研究了一种搜索包含句子中每个单词的每个字符串的方法 样本:Linq搜索字符串单词分隔字符串,linq,search,Linq,Search,我有一张绳子的清单。我想在里面搜索并返回一个新列表。搜索值是一个字符串(句子)。每个单词都被一个空格分开 因此,我研究了一种搜索包含句子中每个单词的每个字符串的方法 样本: list = {"abcdef", "abc", "ab", "cd ab"} search "ab" => return list with "abcdef", "abc", "ab", "cd ab" search "abc" => return list with "abcdef", "abc" sear
list = {"abcdef", "abc", "ab", "cd ab"}
search "ab" => return list with "abcdef", "abc", "ab", "cd ab"
search "abc" => return list with "abcdef", "abc"
search "ab cd" => return list with "abcdef","cd ab"
这很简单,但我不知道如何在一个命令中使用Linq。差不多
if l.contains(list)
其中包含检查列表中的每个元素
这可能很简单,我只是问怎么做。或者是一个链接到另一个我没有看到的帖子
谢谢棘手的是你最后一例“ab cd”
if (list.Any(w => w.Contains(something))
var list=新列表{“abcdef”、“abc”、“ab”、“cd ab”};
var result=list.Where(w=>ab cd.Split().All(s=>w.Contains));
看起来不错,很有效。没有测试过完全的证据,但看起来像那样。坦克你
var list = new List<string> {"abcdef", "abc", "ab", "cd ab"};
var result = list.Where (w => "ab cd".Split().All (s => w.Contains(s)));