本文介绍了比较与非英文字符的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要比较字符串在网站上搜索机制。我使用C#。我尝试了两种方式:
I need to compare strings for a search mechanism on a web site. I use C#. I tried two ways:
consultants.Where(x =>
x.Description.ToLower().Contains(vm.Description.ToLower()));
和
consultants.Where(x =>
Regex.IsMatch(x.Description, vm.Description, RegexOptions.IgnoreCase));
无论做工精细的所有英文字符。所以,如果我搜索,比如说,英语,那也没问题。但只要我尝试搜索包含非英语字符的字符串,这是行不通的。举例来说,如果我试图寻找它不返回任何单词språk(瑞典语言)。
Both work fine for all English characters. So if I search for, say, "english", that's no problem. But as soon as I try searching for a string that contains non-English characters, it doesn't work. For example, if I try searching for the word "språk" ("language" in Swedish) it returns nothing.
这是为什么,我该怎么解决呢?
Why is that, and how can I solve it?
推荐答案
使用
String.Equals(c, vm, StringComparison.OrdinalIgnoreCase)
或
c.IndexOf(vm, StringComparison.OrdinalIgnoreCase)
序
表示统一code,字节每字节,培养独立的比较。
Ordinal
means Unicode, byte-per-byte, culture-independent comparison.
这篇关于比较与非英文字符的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!