从不区分大小写的内容中搜索 [英] search from case Insensitive

查看:107
本文介绍了从不区分大小写的内容中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(from ci in list
where ci.Subject.Contains(emailSubject)

select ci).ToList<unreademails>();
</unreademails>



我用上述代码在数据网格中搜索,但我需要从不区分大小写的位置搜索,请告诉我我该怎么做



i wort above code for search in data grid but i need to search from case Insensitive pls tell me how can i do it

推荐答案

看看是否可以使用ci.subject..IndexOf(temp,StringComparison.CurrentCultureIgnoreCase) >= 0; .


我不知道这是否行得通,因为我自己还没有尝试过,但是您可以尝试使用类似的方法
I don''t know if this will work, as I haven''t tried it myself, but you could try something like
(from ci in list
where ci.Subject.ToUpper().Contains(emailSubject.ToUpper())
select ci).ToList();


.NET列表不支持显式设置使用的比较器.这意味着您应该解决此问题.您可以通过多种方法解决此问题:
1.仅适用于大写/小写.
2.手动扫描列表并使用String.Compare 代替IList.Contains.
3,对集合元素进行适当的比较,可以通过实现IComparerIComparable来实现.
.NET list doesn''t support explicitly setting comparer used.This means that you should work around this.You have several ways to solve the problem:
1.work in uppercase/lowercase only.
2.scan manually the list and use String.Compare instead of IList.Contains.
3.Implement proper comparer of your collection elements.You could do it by implementing IComparer or IComparable.


这篇关于从不区分大小写的内容中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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