Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq搜索字符串单词分隔字符串_Linq_Search - Fatal编程技术网

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)));