将非ASCII字符与等效的ASCII字符匹配 [英] Match non-ascii characters with equivalent ascii charaters
本文介绍了将非ASCII字符与等效的ASCII字符匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我的C#应用程序允许用户搜索我从Web服务获得的记录.
我希望用户能够使用纯ascii搜索文本对具有非ascii记录(带有重音符号,波浪号等的字符)的字段进行搜索.
例如,当用户输入搜索文本"Abrqaus"时,我想返回一个搜索字段值为Ãbrqaus"的记录.
我该怎么办.
致谢
Hello,
My C# application allows users to search for records which I get from a webservice.
I want users to be able to search against a field which has records with non-ascii (characters with accents, tildes etc) with pure ascii search texts.
For example I want to return a record with searchfield value "Ãbrqaus" when my user enters the search text "Abrqaus".
How best can I go about this.
Kind Regards
推荐答案
这是一个不错的选择.关键字搜索是变音符号" !!!在google中使用它,答案就会出来:-D
祝你好运!
This is a nice one. The key search word for this is "diacritics"!!! Use this in google and the answers will come :-D
Good luck!
我是用google找到的:
I found this using google:
public static string RemoveDiacritics(string s)
{
string normalizedString = s.Normalize(NormalizationForm.FormD);
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < normalizedString.Length; i++)
{
char c = normalizedString[i];
if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)
stringBuilder.Append(c);
}
return stringBuilder.ToString();
}
这篇关于将非ASCII字符与等效的ASCII字符匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文