总结:
- 我曾经使用过的术语
寻找似乎是“自然的”
种类”。
-
对于操作系统中的行为:
- 对于 Windows(版本 >= XP),Windows 资源管理器利用自然
种类。
- 对于 Linux 终端:使用“ls -v”而不是普通的“ls”以获得自然效果
种类。
对于在 Delphi 中编程,请使用 StrCmpLogicalW Windows API 来获得自然排序。
- For programing in Delphi & Kylix & Lazarus, use hand-crafted functions to get
natural sort:
- (1) Martin Pool 的用于自然顺序字符串比较的 Delphi 包装器。
http://irsoft.de/web/strnatcmp-and-natsort-for-delphi http://irsoft.de/web/strnatcmp-and-natsort-for-delphi
- (2)来自davekeolle站点的其他语言的字母排序算法代码。
http://www.davekoelle.com/alphanum.html http://www.davekoelle.com/alphanum.html
- (3)其他知识页面:
http://www.codinghorror.com/blog/2007/12/sorting-for- humans-natural-sort-order.html 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://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://groups.google.com/group/borland.public.delphi.language.delphi.general/browse_thread/thread/1141d49f8bbba577
http://objectmix.com/delphi/401713-alphanumeric-sort-routine-delphi.html http://objectmix.com/delphi/401713-alphanumeric-sort-routine-delphi.html
=========================
以下文件名将在 Windows 资源管理器中排序,如下所示:
测试_1_测试.txt
测试_2_测试.txt
test_11_test.txt
test_12_test.txt
test_21_test.txt
test_22_test.txt
例如,如果我将它们放入 TStringList 实例并调用 Sort,则排序顺序如下:
测试_1_测试.txt
test_11_test.txt
test_12_test.txt
测试_2_测试.txt
test_21_test.txt
test_22_test.txt
为了记录,上述文件名将在 Cygwin 的 rxvt 终端或 CentOS 等 Linux 发行版的 xterm 终端中排序,如下所示:
test_11_test.txt
test_12_test.txt
测试_1_测试.txt
test_21_test.txt
test_22_test.txt
测试_2_测试.txt
您能帮忙评论一下如何理解这种排序行为的差异吗?此外,是否可以得到与 Windows 资源管理器中相同的顺序?任何建议表示赞赏!
PS:我的 Windows 区域设置设置为中文,但我认为英语区域设置也是如此。
StrCmp逻辑W http://msdn.microsoft.com/en-us/library/bb759947%28v=vs.85%29.aspx能够处理数字,另一种选择是比较字符串 http://msdn.microsoft.com/en-us/library/dd317759%28v=vs.85%29.aspx
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)