[英]Search in list with link ignore case sensitive
I need to do is search that search of list of string and if I put for example 我需要做的是搜索字符串列表,如果我举个例子
String like N or name or na I will get all the following entries 像N或name或na这样的字符串,我将获得以下所有条目
How should I do that? 我应该怎么做?
I try with the following code which is not working fine if the word 我尝试使用以下代码,如果该单词不能正常工作
myname
name
name1
NAME
n
N
Run
SearchValue = (from stp in SearchValue where stp.Description.Contains(_searchString) select stp).ToList<Serv>();
You have to use IndexOf
+ StringComparison.CurrentCultureIgnorecase
: 您必须使用IndexOf
+ StringComparison.CurrentCultureIgnorecase
:
SearchValue = SearchValue
.Where(sv => sv.Description.IndexOf(_searchString, StringComparison.CurrentCultureIgnoreCase) >= 0)
.ToList();
You can use IndexOf
which supports case-insensitive comparison: 您可以使用支持不区分大小写的比较的IndexOf
:
SearchValue = (from stp in SearchValue
where stp.Description.IndexOf(_searchString,
StringComparison.InvariantCultureIgnoreCase) >= 0
select stp).ToList<Serv>();
If you want a culture-aware comparison, you can use CurrentCultureIgnoreCase
. 如果要进行文化意识的比较,可以使用CurrentCultureIgnoreCase
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.