LINQ 如何搜索 UNICODE 值
帮助我在 LINQ 中搜索 UNICODE 值,当我编写 LINQ 来搜索不是 UNICODE 的字符串时,它工作正常,但字符串是 UNICODE,我的查询不会搜索到任何内容。
Menus.Where(e => e.Name.ToLower().Contains(keyword.ToLower()))
.OrderBy(e => e.Order)
.ThenBy(e => e.Name)
.ToList();
它在没有 Unicode 字符串的情况下工作得很好
"AMERICAN BREAFAST: CHOICE OF FRIED EGG OR OMELETE SERVED WITH CRISPY BACON, SAUSAGE, SAUTEED TOMATO AND TOAST"
,但是当我搜索像这样的 Unicode 字符串时,
"Bữa ăn sáng kiểu Mỹ: chọn giữa trứng chiên hoặc trứng cuộn dùng kèm thịt xông khói, xúc xích, cà chua xào và bánh mì nướng"
它就不再工作了。请帮我解决它。非常感谢
Help me to search UNICODE values in LINQ, when i write a LINQ to search a string not UNICODE , it work fine but string is UNICODE, my query does not search out anything.
Menus.Where(e => e.Name.ToLower().Contains(keyword.ToLower()))
.OrderBy(e => e.Order)
.ThenBy(e => e.Name)
.ToList();
It work fine with none Unicode string like
"AMERICAN BREAFAST: CHOICE OF FRIED EGG OR OMELETE SERVED WITH CRISPY BACON, SAUSAGE, SAUTEED TOMATO AND TOAST"
but when i search a unicode string like
"Bữa ăn sáng kiểu Mỹ: chọn giữa trứng chiên hoặc trứng cuộn dùng kèm thịt xông khói, xúc xích, cà chua xào và bánh mì nướng"
it does not work anymore. please help me fix it. thanks so much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法重现您的问题,但是由于
string.Contains
使用序数区域性进行比较,因此它可能错误地匹配了某些字符。您可能需要将 where 子句更改为Where(e => e.IndexOf(keyword,StringComparison.CurrentCultureIgnoreCase)>=0)
以避免文化问题。I wasn't able to reproduce your issue, however it's possible that since
string.Contains
uses the ordinal culture for comparisons, it's incorrectly matching some characters. You may want to change your where clause toWhere(e => e.IndexOf(keyword,StringComparison.CurrentCultureIgnoreCase)>=0)
to avoid culture issues.首先,你提供的英文字符串实际上是Unicode的。
其次,这一类问题的根源有几个可能的定位:
First of all, the English string you provided is actually Unicode.
Second, this category of problem has several possible loci for the source of the problem: