如何在Windows资源管理器中获得Delphi中的排序顺序? [英] How to get the sort order in Delphi as in Windows Explorer?
问题描述
总结:
- 我已经
寻找的术语似乎是自然
排序 -
对于操作系统中的行为:
- 对于Windows(版本= = ),Windows资源管理器使用自然
排序。 - 对于Linux终端:使用ls -v而不是纯粹的ls来获取自然
排序。 li>
- 对于Windows(版本= = ),Windows资源管理器使用自然
-
对于Delphi中的编程,使用StrCmpLogicalW Windows API来进行自然排序。
- 在Delphi& Kylix&拉撒路,使用手工制作功能获得
自然排序:
- (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
< a href =http://objectmix.com/delphi/401713-alphanumeric-sort-routine-delphi.html> 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.tx t
test_22_test.txt
为了记录,上述文件名将在rxvt终端中Cygwin或xterm终端的Linux发行版,如CentOS,如下所示:
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语言环境设置为中文,但我会认为英文语言环境相同。
StrCmpLogicalW 能够处理数字,另一种替代方法是 CompareString
Summarization:
- The terminology that I have been looking for seems to be "natural sort".
For behaviors in operating systems:
- For Windows (version >= XP), Windows Explorer utilizes natural sort.
- For Linux terminals: use "ls -v" instead of plain "ls" to get natural sort.
For programing in Delphi, use StrCmpLogicalW Windows API to get natural sort.
- For programing in Delphi & Kylix & Lazarus, use hand-crafted functions to get
natural sort:
- (1) Delphi wrapper for Natural Order String Comparison by Martin Pool.
http://irsoft.de/web/strnatcmp-and-natsort-for-delphi - (2) Codes of alphanum sorting algorithm in other languages from davekeolle site.
http://www.davekoelle.com/alphanum.html - (3) Other knowledgable pages:
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) Delphi wrapper for Natural Order String Comparison by Martin Pool.
==========================
The following file names will be ordered in the Windows Explorer as shown below:
test_1_test.txt
test_2_test.txt
test_11_test.txt
test_12_test.txt
test_21_test.txt
test_22_test.txt
If, for example, I put them in a TStringList instance and call Sort, the sorted order is as below:
test_1_test.txt
test_11_test.txt
test_12_test.txt
test_2_test.txt
test_21_test.txt
test_22_test.txt
And for record, the above file names will be ordered in the rxvt terminal of Cygwin or xterm terminal of Linux distributions such as CentOS as shown below:
test_11_test.txt
test_12_test.txt
test_1_test.txt
test_21_test.txt
test_22_test.txt
test_2_test.txt
Could you help to comment on how to understand this difference of sorting behaviors? Furthermore, is it possible to get the same order as in Windows Explorer? Any suggestion is appreciated!
PS: My Windows locale is set to Chinese but I would think the same for English locale.
StrCmpLogicalW is able to handle numbers, the other alternative is CompareString
这篇关于如何在Windows资源管理器中获得Delphi中的排序顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!