为什么是“zzz"?-le "~~~";错误的?
正如标题所说,为什么会发生这种情况?
As the title says, why does this happen?
PS C:\temp> "zzz" -le "~~~"
False
PS C:\temp> "~~~" -le "zzz"
True
"~" 是倒数第二个 ASCII 字符.我无法理解它出现在z"之前的排序规则.
"~" is the next to last ASCII character. I cannot understand a collation where it comes before "z".
简短的回答是:因为它使用 [String]::Compare()
并且返回相同的结果.
The short answer is: because it uses [String]::Compare()
and that returns the same result.
更长的答案是:它不是 ASCII 值比较.这取决于文化信息和比较选项,默认是使用 Word Sort.
The longer answer is: it's not an ASCII value compare. It depends on both culture info and comparison options, and the default is to use Word Sort.
比较使用当前文化来获取特定于文化的大小写规则和字母顺序等信息个别字符.例如,文化可以指定某些字符组合被视为单个字符,或以特定方式比较大写和小写字符,或者字符的排序顺序取决于字符在它之前或之后.
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.
比较是使用单词排序规则进行的.更多有关单词、字符串和序数排序的信息,请参阅System.Globalization.CompareOptions一>.
The comparison is performed using word sort rules. For more information about word, string, and ordinal sorts, see System.Globalization.CompareOptions.
示例
[string]::Compare('z','~')
# 1
[string]::Compare('~','z')
# -1
[string]::Compare('z','~',[cultureinfo]::CurrentCulture,[System.Globalization.CompareOptions]::Ordinal)
# -4
[string]::Compare('~','z',[cultureinfo]::CurrentCulture,[System.Globalization.CompareOptions]::Ordinal)
# 4