c# - Linq 与部分匹配相交
问题描述
对于 Linq 查询中的部分单词匹配,如何让“相交”返回 true?我需要一种.Contains() .Intersect()
混合体。
List<string> sParams = new List<string>(){"SAND", "PURPLE"};
//One of my Prices has the color "Sanddust"
Prices.Where(x => x.Color.ToUpper().Split(null).Intersect(sParams).Any());
上面的查询只返回精确的字符串匹配相交,但我需要返回 true,因为字符串“SANDDUST”包含“SAND”。
解决方案
为什么需要相交?只需使用任何包含。
Prices.Where(x => sParams.Any(s => x.Color.ToUpper().Contains(s)));
推荐阅读
- windows - Win 10 Bat 禁用/启用用户帐户
- amazon-web-services - AWS CDK IAM 联合和用户 IamRoleAccess?
- python - Numpy - 如何删除尾随的 N * 8 个零
- assembly - ARM 汇编,查找字符是大写、小写还是特殊字符
- django - 如何记录我的 django 服务器发出的请求?
- vue.js - Apexcharts 十字准线工具提示
- java - 将行为添加到 Wicket 选项卡
- c# - 获取 VS 2017 中列出的 C# 7.3
- php - 我有一个下面的数组,其中一些相同的键具有不同的值。如何在 PHP 中将相同的键值与该键组合?我正在使用 WAMP,Codeigniter
- scala - `org.quartz.core.jobrunshell throw an unhandled exception`异常的原因是什么?