问题比较法国的字符I [英] Problem comparing French character Î

查看:155
本文介绍了问题比较法国的字符I的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当比较法兰西岛和岛,C#不认为这些是是相同的。

When comparing "Île" and "Ile", C# does not consider these to be to be the same.

    string.Equals("Île", "Ile", StringComparison.InvariantCultureIgnoreCase)

对于所有其他重音字符我所遇到的比较正常工作。

For all other accented characters I have come across the comparison works fine.

有另一个比较函数,我应该使用?

Is there another comparison function I should use?

推荐答案

您指定要比较使用固定区域性的比较规则的字符串。显然,在不变的文化,两个字符串是不相等。

You are specifying to compare the strings using the Invariant culture's comparison rules. Evidently, in the invariant culture, the two strings are not considered equal.

您可以使用的String.Compare,并提供您要比较字符串的文化特定文化的方式对它们进行比较:

You can compare them in a culture-specific manner using String.Compare and providing the culture for which you want to compare the strings:

if(String.Compare("Île", "Ile", new CultureInfo("fr-FR"), CompareOptions.None)==0)

请注意,在法国文化中,这些字符串也被认为是不同的。我包括例子来说明,它是定义的排序规则的培养。你也许可以找到适合您需求的文化,或者建立一个自定义一个具有所需的比较规则,但它可能不是你想要的。

Please note that in the french culture, those strings are also considered different. I included the example to show, that it is the culture that defines the sort rules. You might be able to find a culture that fits your requirements, or build a custom one with the needed compare rules, but that it probably not what you want.

有关正常化字符串的一个很好的例子,所以没有口音的看看这个问题。正火字符串后,你就可以对它们进行比较,并考虑他们平等的。这很可能是实现您的要求最简单的方法。

For a good example of normalizing the string so there are no accents, have a look at this question. After normalizing the string, you would be able to compare them and consider them equal. This would probably be the easiest way to implement your requirement.

这不仅是我的性格有在InvariantCulture的这种行为,这种说法也返回false:

It is not just the I character that has this behaviour in the InvariantCulture, this statement also returns false:

String.Equals("Ilê", "Ile", StringComparison.InvariantCultureIgnoreCase)

该框架做正确的事 - 这些角色其实都是不同的(有不同的含义)在大多数培养物,因此,它们不应该被认为是相同的。

The framework does the right thing - those characters are in fact different (has different meaning) in most cultures, and therefore they should not be considered the same.

这篇关于问题比较法国的字符I的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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