如何在Windows资源管理器中获得Delphi中的排序顺序? [英] How to get the sort order in Delphi as in Windows Explorer?

查看:142
本文介绍了如何在Windows资源管理器中获得Delphi中的排序顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总结:


  1. 我已经
    寻找的术语似乎是自然
    排序

  2. 对于操作系统中的行为:




    • 对于Windows(版本= = ),Windows资源管理器使用自然
      排序。

    • 对于Linux终端:使用ls -v而不是纯粹的ls来获取自然
      排序。 li>

  3. 对于Delphi中的编程,使用StrCmpLogicalW Windows API来进行自然排序。


  4. 在Delphi& Kylix&拉撒路,使用手工制作功能获得
    自然排序:

============= =============



以下文件名将在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:

  1. The terminology that I have been looking for seems to be "natural sort".
  2. 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.
  3. For programing in Delphi, use StrCmpLogicalW Windows API to get natural sort.

  4. For programing in Delphi & Kylix & Lazarus, use hand-crafted functions to get natural sort:

==========================

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆