• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

应该怎么这些比较回报

用户头像
it1352
帮助1

问题说明

我已经得到了多数民众赞成使用的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)?

正确答案

#1

从的的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) .

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfgaae
系列文章
更多 icon
同类精品
更多 icon
继续加载