应该怎么这些比较回报? [英] What should these comparisons return?

查看:106
本文介绍了应该怎么这些比较回报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了多数民众赞成使用的String.Compare(字符串,字符串)在一定值进行排序的应用程序。我想不通的事情是为什么1022比较小于10-23和10-23比喻为小于1024。

I've got an application that's using string.compare(string,string) to sort some values. The thing I can't figure out is why "1022" compares as less than "10-23" and "10-23" compares as less than "1024".

有没有具体的有价值的东西 - 这会导致这样的结果?会的String.Compare那过载产生相同的结果与(与破折号号)相同的数据类型不同的区域性设置?

Is there something specific to the value of "-" that causes this result? Will that overload of string.compare give the same result with different culture settings for the same type of data (numbers with dashes)?

推荐答案

从的的String.Compare(字符串,字符串)

的比较是使用单词排序规则来执行。

The comparison is performed using word sort rules.

进一步

.NET框架使用三个不同的排序方式:字排序,字符串排序,并依次排序。字排序执行字符串的文化敏感的比较。一些非字母数字字符可能分配给他们特殊的权重。例如,连字符( - )可能具有分配给它的一个非常小的重量,使鸡舍和合作社彼此相邻出现在排序列表。字符串排序类似于字排序,但没有特殊的情况下。因此,所有非字母数字符号来之前,所有字母数字字符。基于字符串的每个元素的统一code值依次排序比较字符串。

The .NET Framework uses three distinct ways of sorting: word sort, string sort, and ordinal sort. Word sort performs a culture-sensitive comparison of strings. Certain nonalphanumeric characters might have special weights assigned to them. For example, the hyphen ("-") might have a very small weight assigned to it so that "coop" and "co-op" appear next to each other in a sorted list. String sort is similar to word sort, except that there are no special cases. Therefore, all nonalphanumeric symbols come before all alphanumeric characters. Ordinal sort compares strings based on the Unicode values of each element of the string.

这是迈克尔·卡普兰在这里更多的细节: A和排序键,部分的对9(又名不总是传递的,而是准时,划分)

Some more details from Michael Kaplan here: A&P of Sort Keys, part 9 (aka Not always transitive, but punctual and punctuating) .

这篇关于应该怎么这些比较回报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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