【发布时间】:2011-07-05 07:37:19
【问题描述】:
总结:
- 我使用过的术语 寻找似乎是“自然的 排序”。
-
对于操作系统中的行为:
- 对于 Windows(版本 >= XP),Windows 资源管理器利用自然 排序。
- 对于 Linux 终端:使用“ls -v”而不是普通的“ls”来获得自然 排序。
对于在 Delphi 中编程,使用 StrCmpLogicalW Windows API 来获得自然排序。
- 对于在 Delphi & Kylix & Lazarus 中编程,使用手工制作的函数来获取
自然排序:
- (1) Martin Pool 用于自然顺序字符串比较的 Delphi 包装器。
http://irsoft.de/web/strnatcmp-and-natsort-for-delphi - (2) 来自davekeolle网站的其他语言的字母排序算法代码。
http://www.davekoelle.com/alphanum.html - (3) 其他知识页面:
http://www.codinghorror.com/blog/2007/12/sorting-for-humans-natural-sort-order.html
http://objectmix.com/delphi/722211-natural-sorting-optimizing-working-solution.html
http://groups.google.com/group/borland.public.delphi.language.delphi.general/browse_thread/thread/1141d49f8bbba577
http://objectmix.com/delphi/401713-alphanumeric-sort-routine-delphi.html
- (1) Martin Pool 用于自然顺序字符串比较的 Delphi 包装器。
===========================
以下文件名将在 Windows 资源管理器中按如下顺序排列:
test_1_test.txt
test_2_test.txt
test_11_test.txt
test_12_test.txt
test_21_test.txt
test_22_test.txt
例如,如果我把它们放在一个 TStringList 实例中并调用 Sort,排序顺序如下:
test_1_test.txt
test_11_test.txt
test_12_test.txt
test_2_test.txt
test_21_test.txt
test_22_test.txt
为了记录,上述文件名将在Cygwin的rxvt终端或Linux发行版如CentOS的xterm终端中排序,如下所示:
test_11_test.txt
test_12_test.txt
test_1_test.txt
test_21_test.txt
test_22_test.txt
test_2_test.txt
您能帮忙评论一下如何理解排序行为的这种差异吗?此外,是否可以获得与 Windows 资源管理器中相同的顺序?任何建议表示赞赏!
PS:我的 Windows 区域设置为中文,但我认为英文区域设置相同。
【问题讨论】:
-
我之前注意到了这一点。 AFAICS,较新的 Windows 版本识别文件名中的数字,并将数字排序为数字而不是文本。
-
@ax:非常感谢您提供的信息!我现在就读!
-
名称中包含数字的文件和文件夹的排序顺序:support.microsoft.com/kb/319827
-
@Jørn E. Angeltveit:谢谢,但这是猜测还是来自官方消息?
标签: windows sorting delphi collation