StrCmpLogicalW字符串逻辑比较函数

来源:互联网 发布:coreldraw绘制软件下载 编辑:程序博客网 时间:2024/06/06 12:32
今天在CSDN上看到有人讨论关于Windows资源管理器的排序方式规则,Windows是有这个API函数来解决这个事情的:StrCmpLogicalW。

/*

Compares two Unicode strings. Digits in the strings are considered as numerical content rather than text. This test is not case sensitive.

Syntax

int StrCmpLogicalW(          LPCWSTR psz1,    LPCWSTR psz2);

Parameters

psz1
[in] A pointer to the first null-terminated string to be compared.
psz2
[in] A pointer to the second null-terminated string to be compared.

Return Value

  • Returns zero if the strings are identical.
  • Returns 1 if the string pointed to by psz1 has a greater value than that pointed to by psz2.
  • Returns -1 if the string pointed to by psz1 has a lesser value than that pointed to by psz2.

*/

Windows Vista、Windows XP 和 Windows Server 2003 对名称中包含数字的文件和文件夹的排序顺序与 Windows 2000 中使用的排序顺序不同。


Windows Vista、Windows XP 和 Windows Server 2003:
Ie4_01
Ie4_128
Ie5
Ie6
Ie401sp2
Ie501sp2

Windows 2000:
Ie4_01
Ie4_128
Ie401sp2
Ie5
Ie501sp2
Ie6
默认情况下,较新的排序顺序将文件和文件夹名称中的字符串视作数值内容而不是文本。文件夹和文件名称中的数字按照其数值大小进行排序。

在本例中,401 在数值上大于 6。因此,在按照名称以升序对文件夹进行排序时,Ie401sp2 文件夹将在 Ie6 文件夹之后

列出。在下面的示例中,请注意名称中包含数字的以下文件的排序方式。
Windows Vista、Windows XP 和 Windows Server 2003:
 5.txt
11.txt
88.txt
Windows 2000:
11.txt
5.txt

88.txt

注意StrCmpLogicalW与StrCmpI的区别:

   StrCmpLogical认为字符串中的数字是其对应的数值,所以它的排序结果:

    

2string3string20stringst2ringst3ringst20ringstring2string3string20
 StrCmpI认为字符串中的数字仅仅是一个文本,所以它的排序结果:

20string2string3stringst20ringst2ringst3ringstring2string20string3

Over。