StrCmpLogicalW字符串逻辑比较函数

本文介绍了Windows资源管理器中文件和文件夹的排序规则,特别是对于包含数字的名称,Windows Vista、XP和Server 2003使用StrCmpLogicalW函数按数值而非文本进行排序,与Windows 2000的排序方式不同。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天在优快云上看到有人讨论关于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认为字符串中的数字是其对应的数值,所以它的排序结果:

    

2string
3string
20string
st2ring
st3ring
st20ring
string2
string3
string20
 StrCmpI认为字符串中的数字仅仅是一个文本,所以它的排序结果:

20string
2string
3string
st20ring
st2ring
st3ring
string2
string20
string3

Over。


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值