允许重音符号被搜索? [英] allow accented characters to be searchable?

查看:149
本文介绍了允许重音符号被搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决的:

我用下面的code:

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

  

可能重复:
  <一href="http://stackoverflow.com/questions/359827/ignoring-accented-letters-in-string-comparison">Ignoring在字符串比较重音字母

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

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

使用

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

返回-1

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

也返回-1

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

解决方案

如果你正在做你自己的字符串比较,那么你可以通过指定<一个忽略重音href="http://msdn.microsoft.com/en-us/library/system.globalization.compareoptions%28v=vs.100%29.aspx"相对=nofollow> 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

这篇关于允许重音符号被搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆