string 数组与 string 求交集
有一个string[] s1={"a","b","c","d","e","ac","ab","bc","ade"}
和一个string s2="abc";
现在想求这两的交集,结果应该也是个数组
string s3={"a","b","c","ac","bc"}
最好能用linq 解答
谢谢
linq
string
------解决方案-------------------- string[] s1 = { "a", "b", "c", "d", "e", "ac", "ab", "bc", "ade" };
string s2 = "abc";
var s3 = (from q in s1
where s2.IndexOf(q) >= 0
select q).ToArray<string>();
------解决方案--------------------
string[] s1 = { "a", "b", "c", "d", "e", "ac", "ab", "bc", "ade" };
string s2 = "abc";
string[] vs = s1.Where(v => s2.Contains(v)).ToArray();
------解决方案--------------------//string s3={"a","b","c","ab","bc"} //第四个是ab吧?
var ary = s1.Where(v => s2.Contains(v)).ToList();