Linq包含而无需考虑口音 [英] Linq Contains without considering accents

查看:37
本文介绍了Linq包含而无需考虑口音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获得所有结果,其中文本包含忽略所有重音的特定单词.

I need to get all the results where the text contains a particular word ignoring all accents.

现在我有以下内容:

filtered = result.Where(p => p.@string.ToString().ToUpper().Contains(word));

或简化版本:

filtered = result.ToUpper().Contains(word));

如何使包含"语句忽略重音?

How can I make the "Contains" statement ignore the accents?

预先感谢

推荐答案

在类似的解决方案表格中借用此处:

Borrowing a similar solution form here:

string[] result = {"hello there", "héllo there","goodbye"};

string word = "héllo";

var compareInfo = CultureInfo.InvariantCulture.CompareInfo;

var filtered = result.Where(
      p => compareInfo.IndexOf(p, word, CompareOptions.IgnoreNonSpace) > -1);

这篇关于Linq包含而无需考虑口音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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