Disabling Case sensitivity for my keyword search
This question already has an answer here:
Let's say there is a boolean property CaseSensitive
identifying the search mode. Then you can use string.IndexOf
to solve this by setting the StringComparison
correctly:
StringComparison comparison = CaseSensitive ?
StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;
if (value.Value.IndexOf(txtFilterValue.Text, comparison) >= 0)
{
//Returns true...
}
The whole query can be simply written with LINQ like
private void GetFilteredResults(MessageDetails detail, FilterEventArgs e)
{
bool comparison = CaseSensitive ?
StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;
return detail.MessageValue.Any(v => v.Value.IndexOf(txtFilterValue.Text, comparison) >= 0);
}
链接地址: http://www.djcxy.com/p/13100.html
上一篇: 字符串匹配时出错?
下一篇: 禁用我的关键字搜索的区分大小写