使用多键搜索 [英] Search with multi keys

查看:56
本文介绍了使用多键搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个arraylist

 ArrayList A =  new  ArrayList(){ 芒果  Banana  Potato 番茄}; 
ArrayList B = new ArrayList(){ a o i};



如何检查ArrayList中的项目B包含在ArrayList A中的项目中使用LINQ

Ex:o (arraylist B)包含在Mango,Potato,Tomato

解决方案

试试这个



列表< string> A =  new 列表< string>(){ 芒果  Banana 马铃薯 番茄}; 
List< char> B = new 列表< char>(){' a '' o'' i'};

var C = A.Where(x = > x.IndexOfAny (B.ToArray())> 0 );





使用List而不是ArrayList并将B更改为char列表。



如果你想使用字符串代替,我在LINQ中找不到任何解决方案。

但是,我并不擅长LINQ。



使用正则表达式有效但是。



这段代码会找到'芒果','土豆'和'番茄'。

正则表达式模式= 正则表达式( (go | to )); 
var E = A.Where(x = > pattern.IsMatch(x)) ;


I have two arraylist

ArrayList A = new ArrayList() { "Mango", "Banana", "Potato", "Tomato" };
ArrayList B = new ArrayList() { "a", "o", "i" };


How do I check an item in ArrayList B is contained in an item in ArrayList A with LINQ
Ex: "o"(arraylist B) is contained in "Mango","Potato", "Tomato"

解决方案

Try this

List<string> A = new List<string>() { "Mango", "Banana", "Potato", "Tomato" };
List<char> B = new List<char>() { 'a', 'o', 'i' };

var C = A.Where(x => x.IndexOfAny(B.ToArray()) > 0);



Use List instead of ArrayList and change B to a list of char.

If you want to use strings instead, I could not find any solution within LINQ only.
However, I am not really good at LINQ.

Using a Regular Expression works, though.

This code will find 'mango', 'potato' and 'tomato'.

Regex pattern = new Regex("(go|to)");
var E = A.Where(x => pattern.IsMatch(x));


这篇关于使用多键搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆