的String.Compare行为 [英] string.Compare behavior

查看:145
本文介绍了的String.Compare行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这怎么可能呢? (这是从在VS2008即时窗口)

 的String.Compare?( - ,+)
-1
?的String.Compare( -  0,0)
1
 

解决方案

从上的的String.Compare (重点煤矿):

  

比较使用当前的文化,以获得区域性特定信息,如大小写规则和单个字符的字母顺序。例如,一种文化可以指定字符的某些组合被视为单个字符,或大小写字符以特定方式进行比较,或一个字符的排序顺序取决于$ P $字符pcede或按照它

How this can be ? (This is taken from the immediate window in VS2008)

?string.Compare("-", "+")
-1
?string.Compare("-0", "+0")
1

解决方案

From the remarks on String.Compare (emphasis mine):

The comparison uses the current culture to obtain culture-specific information such as casing rules and the alphabetic order of individual characters. For example, a culture could specify that certain combinations of characters be treated as a single character, or uppercase and lowercase characters be compared in a particular way, or that the sorting order of a character depends on the characters that precede or follow it.

这篇关于的String.Compare行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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