如果搜索文本和列表中的项目大小写相同(小写/大写),我有以下代码可以使用。如果有混合外壳,则无法正常工作。我们怎样才能使搜索不区分大小写。
var text = "c";
var myStrings = new List<string>() { "Aa", "ACB", "cc" };
var regEx = new System.Text.RegularExpressions.Regex(text);
var results = myStrings
.Where<string>(item => regEx.IsMatch(item))
.ToList<string>();
编辑:
我需要将不区分大小写的字符串传递给方法,我该怎么做...
public ActionResult GetItems(string text)
{
ContextObject contextObject = new ContextObject();
TransactionHistory transactionhistory = new TransactionHistory();
System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex(text, RegexOptions.IgnoreCase);
var items = transactionhistory.GetItems(contextObject, text);
return Json(items, JsonRequestBehavior.AllowGet);
}
最佳答案
尝试像这样声明你的正则表达式
Regex regEx = new Regex(text, RegexOptions.IgnoreCase);
关于c# - LINQ 中不区分大小写的 LIKE 条件(使用正则表达式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18503201/