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

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

问题描述

有关我的回答问题我要比较两个字符。我认为正常的 char.CompareTo()方法可以让我指定的的CultureInfo 的,但事实并非如此。



所以我的问题是:如何比较两个字符和指定的CultureInfo进行比较


< DIV CLASS =h2_lin>解决方案

有确实比较字符和字符串之间的差异。让我试着解释的基本问题,这是很简单:一个字符总是代表一个单个Unicode点。比较字符始终没有任何看做自己的平等意义上的代码点进行比较。



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


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.

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

解决方案

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.

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天全站免登陆