问题描述
解决的:
我用下面的code:
VAR compareinfo = CultureInfo.CurrentCulture.CompareInfo;
VAR指数= compareinfo.IndexOf(STRA,STRB,CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
返回索引> -1;
我有一个公共信息亭应用程序,用户用它来搜索一个景点。说我有一个店铺名称与咖啡厅字。亭子只允许通过屏幕上的键盘的英文字母输入。当我在咖啡馆型(不带重音E)的问题是搜索是无效的,因为用户不能输入字符E。我希望应用程序允许正常E要被搜索到所有的重音e和同样对所有其他各字符。我怎样才能做到这一点?
编辑:店铺名称是布鲁斯咖啡馆和我搜索咖啡馆,它应该显示在我的搜索结果。
使用
的String.Compare(布鲁斯咖啡馆,咖啡馆,CultureInfo.CurrentCulture,CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace)
返回-1
和
的String.Compare(本 - 古里安大学(BGU),咖啡馆,CultureInfo.CurrentCulture,CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace)
也返回-1
我不知道为什么会这样...
如果你正在做你自己的字符串比较,那么你可以通过指定 CompareOptions.IgnoreNonSpace 到接受一个CompareOptions参数,例如
SOLVED:
I used the following code:
var compareinfo = CultureInfo.CurrentCulture.CompareInfo;
var index = compareinfo.IndexOf(strA, strB, CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
return index > -1;
I have a public Kiosk application where users use it to search for a place of interest. Say I have a shop name with the Café word. The kiosk only allows input of English alphabets through an on-screen keyboard. The problem is when I type in Cafe(without the accented é) the search is not valid because the user could not input the character é. I want the application to allow the normal e to be searchable to all accented e and likewise for all other respective characters. How can i do that?
EDIT:the shop name is "Bruce Café" and i search for "cafe" and it should show in my search results.
using
string.Compare("Bruce Café", "cafe", CultureInfo.CurrentCulture, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace)
returns -1
and
string.Compare("Ben-Gurion University (BGU)", "cafe", CultureInfo.CurrentCulture, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace)
also returns -1
which i don't know why is it so...
If you are doing your own string comparisons, then you can ignore the accents by specifying CompareOptions.IgnoreNonSpace to one of the string comparison methods that accepts a CompareOptions parameter, for example this String.Compare
这篇关于允许重音符号被搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!