如何比较字符(尊重文化) [英] How to compare characters (respecting a culture)

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

问题描述

有关我在此问题中的答案,我必须比较两个字符。我认为正常的 char.CompareTo()方法允许我指定一个 CultureInfo ,但事实并非如此。

For my answer in this question I have to compare two characters. I thought that the normal char.CompareTo() method would allow me to specify a CultureInfo, but that's not the case.

所以我的问题是:如何比较两个字符并指定一个CultureInfo用于比较?

So my question is: How can I compare two characters and specify a CultureInfo for the comparison?

推荐答案

比较字符和字符串的确有一个区别。让我尝试解释一个基本的问题,这是很简单的:一个字符总是代表一个单一的unicode点。比较字符总是比较代码点,而不考虑它们的含义相同。

There is indeed a difference between comparing characters and strings. Let me try to explain the basic issue, which is quite simple: A character always represents a single unicode point. Comparing characters always compares the code points without any regard as to their equal meaning.

如果你想比较字符的含义,你需要创建一个字符串并使用比较方法。这些包括对不同文化的支持。见Guffa的答案如何做。

If you want to compare characters for equal meaning, you need to create a string and use the comparison methods provided there. These include support for different cultures. See Guffa's answer on how to do that.

这篇关于如何比较字符(尊重文化)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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