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

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

问题描述

我有一个应用程序使用string.compare(string,string)来排序一些值。我不能明白的是,为什么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)?

推荐答案

p> string.Compare(String,String)的文档:


使用字词排序规则进行比较。

The comparison is performed using word sort rules.

进一步


.NET Framework使用三种不同的排序方式:字词排序,字符串排序和序数排序。 Word排序执行文化敏感的字符串比较。某些非字母数字字符可能具有分配给它们的特殊权重。例如,连字符( - )可能具有分配给它的非常小的权重,使得coop和coop在排序列表中彼此相邻地出现。字符串排序类似于单词排序,除了没有特殊情况。因此,所有非字母数字符号都在所有字母数字字符之前。

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.

有关Michael Kaplan的更多详细信息:排序键的A& P,第9部分(也称为不总是传递,但是准时和标点化) / a>。

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