允许重音符号被搜索?重音、符号

由网友(庸俗且无趣)分享简介:解决的:我用下面的code:VAR compareinfo = CultureInfo.CurrentCulture.CompareInfo;VAR指数= compareinfo.IndexOf(STRA,STRB,CompareOptions.IgnoreNonSpace | CompareOptions.Igno...

解决的:

我用下面的code:

  VAR compareinfo = CultureInfo.CurrentCulture.CompareInfo;
VAR指数= compareinfo.IndexOf(STRA,STRB,CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
返回索引> -1;
 

  

可能重复:   Ignoring在字符串比较重音字母

我有一个公共信息亭应用程序,用户用它来搜索一个景点。说我有一个店铺名称与咖啡厅字。亭子只允许通过屏幕上的键盘的英文字母输入。当我在咖啡馆型(不带重音E)的问题是搜索是无效的,因为用户不能输入字符E。我希望应用程序允许正常E要被搜索到所有的重音e和同样对所有其他各字符。我怎样才能做到这一点?

编辑: 店铺名称是布鲁斯咖啡馆和我搜索咖啡馆,它应该显示在我的搜索结果。

使用

 的String.Compare(布鲁斯咖啡馆,咖啡馆,CultureInfo.CurrentCulture,CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace)
 

返回-1

苹果mac最容易被忽视的操作技巧,正确使用事半功倍

 的String.Compare(本 - 古里安大学(BGU),咖啡馆,CultureInfo.CurrentCulture,CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace)
 

也返回-1

我不知道为什么会这样...

解决方案

如果你正在做你自己的字符串比较,那么你可以通过指定 CompareOptions.IgnoreNonSpace 到接受一个CompareOptions参数,例如此的String.Compare

SOLVED:

I used the following code:

var compareinfo = CultureInfo.CurrentCulture.CompareInfo;
var index = compareinfo.IndexOf(strA, strB, CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
return index > -1;

Possible Duplicate: Ignoring accented letters in string comparison

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

阅读全文

相关推荐

最新文章