如何确定是否一个字符串包含字符串列表的任何匹配 [英] How to determine if a string contains any matches of a list of strings

查看:99
本文介绍了如何确定是否一个字符串包含字符串列表的任何匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜说我有一个字符串列表:

  VAR listOfStrings =新的List<串GT; {汽车总动员,卡车,渔舟唱晚};

和我有其中有一个名称字段一辆选项。

我想找到,其中的名称相匹配的listOfStrings的项目之一的车辆。

我试图使用LINQ要做到这一点,但似乎无法在瞬间完成它。

  VAR matchingVehicles = Vehicles.Where(V => v.Name ==的listOfStringItem之一)

任何人可以帮助我呢?


解决方案

  Vehicles.Where(V => listOfStrings.Contains(v.Name))

Hi say I have a list of strings:

var listOfStrings = new List<string>{"Cars", "Trucks", "Boats"};

and I have a vehicles options which has a Name field.

I want to find the vehicles where the name matches one of the items in the listOfStrings.

I'm trying to do this with linq but can't seem to finish it at the moment.

var matchingVehicles = Vehicles.Where(v => v.Name == one of the listOfStringItem)

Can anybody help me with this?

解决方案

Vehicles.Where(v => listOfStrings.Contains(v.Name))

这篇关于如何确定是否一个字符串包含字符串列表的任何匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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