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

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

问题描述

总结:

  1. 我使用过的术语寻找似乎是自然的排序".
  2. 对于操作系统中的行为:

  1. The terminology that I have been looking for seems to be "natural sort".
  2. For behaviors in operating systems:

  • 对于 Windows(版本 >= XP),Windows 资源管理器利用自然排序.
  • 对于 Linux 终端:使用ls -v"代替普通的ls"以获得自然排序.

对于在 Delphi 中编程,使用 StrCmpLogicalW Windows API 来获得自然排序.

For programing in Delp use StrCmpLogicalW Windows API to get natural sort.

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

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

以下文件名将在 Windows 资源管理器中排序,如下所示:

The following file names will be ordered in the Windows Explorer as shown below:

test_1_test.txt

test_1_test.txt

test_2_test.txt

test_2_test.txt

test_11_test.txt

test_11_test.txt

test_12_test.txt

test_12_test.txt

test_21_test.txt

test_21_test.txt

test_22_test.txt

test_22_test.txt

例如,如果我将它们放在一个 TStringList 实例中并调用 Sort,则排序顺序如下:

If, for example, I put them in a TStringList instance and call Sort, the sorted order is as below:

test_1_test.txt

test_1_test.txt

test_11_test.txt

test_11_test.txt

test_12_test.txt

test_12_test.txt

test_2_test.txt

test_2_test.txt

test_21_test.txt

test_21_test.txt

test_22_test.txt

test_22_test.txt

为了记录,上述文件名将在 Cygwin 的 rxvt 终端或 CentOS 等 Linux 发行版的 xterm 终端中排序,如下所示:

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_11_test.txt

test_12_test.txt

test_12_test.txt

test_1_test.txt

test_1_test.txt

test_21_test.txt

test_21_test.txt

test_22_test.txt

test_22_test.txt

test_2_test.txt

test_2_test.txt

您能帮忙评论一下如何理解这种排序行为的差异吗?此外,是否可以获得与 Windows 资源管理器中相同的顺序?任何建议表示赞赏!

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:我的 Windows 语言环境设置为中文,但我认为英语语言环境也是如此.

PS: My Windows locale is set to Chinese but I would think the same for English locale.

推荐答案

StrCmpLogicalW 能够处理数字,另一种选择是 比较字符串

StrCmpLogicalW is able to handle numbers, the other alternative is CompareString

这篇关于如何像在 Windows 资源管理器中一样在 Delphi 中获取排序顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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