The information in this article applies to:
SUMMARY
This article provides supplementary information to Section 18.2.2.1
"Comparing and Sorting Strings" in the Windows version 3.1 Software
Development Kit "Programmer's Reference, Volume 1: Overview" manual and the
Windows Help International Overview section. Specifically, this article
provides information about the sort order used by the Windows lstrcmp and
lstrcmpi functions, the location of accented characters in the sort, and
how primary and secondary values, or weights, are important when sorting a
string using these functions. This includes the different behavior of these
functions when a language driver is installed compared to when Windows's
internal sort routine (English/American) is used.
MORE INFORMATIONThe following files are available for download from the Microsoft
Download Center. Click the file names below to download the files: http://www.microsoft.com/downloads/search.aspand then click How to use the Microsoft Download Center. The sort order used by lstrcmp and lstrcmpi is:
The following illustrate the differences in character order ("..." signifies omitted characters): ANSI Order:
Internal (English/American) Sort Routine Order:
Language Driver Order:
Note that the accented characters are intermixed with their alphabetic
counterparts here.
Primary and secondary weights of characters also affect the sort order when a language module is installed. In this case, sorting is done by primary weight for the entire length of the string, then by length, and lastly by secondary weight if the primary weights of all the characters and the lengths of the strings are equal. The secondary (diacritic) weights are important only when there is a tie in the entire string. The internal (English/American) sort routine does not sort extended characters; as mentioned above, they are sorted as punctuation rather than alphabetic characters. Therefore, the internal routines produce completely different results than the language routines in some cases. Character weights are important with case-sensitive sorting also. For example, using lstrcmp will produce: A < a < B < b; it will also produce: Aaa < aaa < Aab. These examples use proper dictionary sort order, but the second example is not necessarily obvious because if A < a, then it seems Aab < aaa should also be true. In that case, it is said that A and a "collide" (that is, their primary weights are the same) and a delayed comparison must be performed if the remainders of the strings are equal. The strings continue to be compared character by character. Because a < b, then aaa < Aab and the comparison is complete. If the strings were equal all the way through (such as Aaa and aaa) then A and a would collide once again. The rest of the strings would be equal, and then the secondary weights of A and a would be checked to determine that Aaa < aaa. EXAMPLES WHEN A LANGUAGE DRIVER IS INSTALLEDNote: Special notation is used below to represent accented characters due to limitations in the distribution media for this article. For example <u umlaut> is used to represent the letter "u", which has an umlaut over it. Likewise, <a tilde> represents the letter "a" accented with a tilde.Nonaccented CharactersThe sort works on a character-by-character comparison, checking primary weights in a string. As soon as the primary (alphabetic) weights show one string greater than the other, the comparison stops. Therefore, sorted lists resemble the following:a Accented CharactersThe secondary (diacritic) weights are important only when there is a tie in the string. For example, in the following sorted list, the characters in the first two strings have identical primary sort weights ("s", "a", "m", "e") and the strings are the same length. Because of the tie in primary weights and string lengths, the secondary weights are then compared. The first difference in secondary weight ("a" versus <a tilde>) breaks the tie. Secondary weights are also a factor when comparing strings 4 and 5 below:
Here is a sorted list using the English (International) driver: aHere is the same list, using the internal [English (American)] routine: <a grave> Additional query words: softlib ALPHSORT.EXE kbfile
Keywords : kbfile kbsample kb16bitonly kbWinOS310 kbIntlDev kbWinOS300 |
Last Reviewed: December 2, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |