StrCmpLogicalW function
Applies to: desktop apps only
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( __in PCWSTR psz1, __in PCWSTR psz2 );
Parameters
- psz1 [in]
-
Type: PCWSTR
A pointer to the first null-terminated string to be compared.
- psz2 [in]
-
Type: PCWSTR
A pointer to the second null-terminated string to be compared.
Return value
Type: int
- 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.
Remarks
This function's ordering schema differs somewhat from StrCmpI, which also compares strings without regard to case sensitivity. Considering digits by their numerical value—as StrCmpLogicalW does—strings are ordered as follows:
2string 3string 20string st2ring st3ring st20ring string2 string3 string20
StrCmpI considers digits in the string only as text so that those same strings are ordered as follows:
20string 2string 3string st20ring st2ring st3ring string2 string20 string3
Note Behavior of this function, and therefore the results it returns, can change from release to release. It should not be used for canonical sorting applications.
Requirements
|
Minimum supported client | Windows XP |
|---|---|
|
Minimum supported server | Windows Server 2003 |
|
Header |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names | StrCmpLogicalW (Unicode) |
Send comments about this topic to Microsoft
Build date: 3/7/2012
The above happens because you probably used std::sort, ie:std::sort(list.begin(), list.end(), [](const TCHAR *a, const TCHAR *b) -> bool { return ::StrCmpLogicalW(a, b) < 0;});result:
std::sort (StrCmpLogicalW):
000
000_A
000_B
00
0 Use qsort instead, ie:int compare_logical(const void *a, const void *b) {
return ::StrCmpLogicalW((const TCHAR *)a, (const TCHAR *)b);
}
qsort(&*list.begin(), list.size(), sizeof(const TCHAR *), compare_logical);result:
qsort (StrCmpLogicalW):
0
00
000
000_A
000_B
If you have the names
0, 00, 000, 000_A, 000_B
I expected it to be sorted
0
00
000
000_A
000_B
But I get
000
000_A
000_B
00
0
- 2/22/2012
- Mathias Svensson