DOCUMENT:Q96748 19-FEB-2002 [win16sdk] TITLE :Detailed Description of lstrcmp and Alphabetic Characters PRODUCT :Microsoft Windows Software Development Kit PROD/VER:WINDOWS:3.0,3.1 OPER/SYS: KEYWORDS: ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Windows Software Development Kit (SDK) versions 3.0, 3.1 ------------------------------------------------------------------------------- SYMPTOMS ======== Executing the following function in the English language returns -1, indicating that a lowercase 'e' is less than an uppercase 'Z': lstrcmp("e","Z"); This is contrary to the order of characters using ASCII sorting. However, it is correct behavior or lstrcmp(). CAUSE ===== lstrcmp() performs a comparison in the same manner as does a real dictionary. Characters are compared in a case-insensitive manner first, then specific details are compared (for example, lowercase versus uppercase). lstrcmp() performs its comparisons by first setting up a primary and secondary weight. The primary weight is the value of the character after converting to uppercase. The secondary weight describes whether the character was originally lowercase or uppercase. Using the standard ASCII table as a guide (0...9ABC...XYZabc...xyz), the following are examples of lstrcmp: "A" < "a" < "B" < "b" "Aaa" < "aaa" < "Aab" In the first example, "A" is less than "a" because: 1. Both characters are converted to uppercase. 2. The primary weights are compared and found equal. 3. Because the primary weights are equal, the secondary weights are compared. It is then determined that "A" is less than "a" because "a" is higher in the ASCII chart. Also in the first example, "a" is less than "B" because: 1. Both characters are converted to uppercase. 2. The primary weights are compared and it is determined that "A" is less than "B" on the ASCII chart. No secondary weight comparison is performed. In the second example, "Aaa" is less than "aaa" following the same logic shown in the comparison of "A" and "a". When two characters are compared and they are equal, this is called a "collision," and "delayed comparison" will be performed using the secondary weight. MORE EXAMPLES ------------- e,a --> E,A --> E>A = 1 e,e --> E,E --> E=E = 0 Because they are equal, the case is checked (secondary weight). e,z --> E,Z --> E E,A --> E>A = 1 e,E --> E,E --> E=E = 1 Because they are equal, the case is checked (secondary weight). e,F --> E,F --> E