Microsoft KB Archive/96748

{|
 * width="100%"|

Detailed Description of lstrcmp and Alphabetic Characters

 * }

Q96748

-

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(&quot;e&quot;,&quot;Z&quot;); 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:

&quot;A&quot; < &quot;a&quot; < &quot;B&quot; < &quot;b&quot;

&quot;Aaa&quot; < &quot;aaa&quot; < &quot;Aab&quot; In the first example, &quot;A&quot; is less than &quot;a&quot; 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 &quot;A&quot; is less than &quot;a&quot; because &quot;a&quot; is higher in the ASCII chart.

Also in the first example, &quot;a&quot; is less than &quot;B&quot; because:


 * 1) Both characters are converted to uppercase.
 * 2) The primary weights are compared and it is determined that &quot;A&quot; is less than &quot;B&quot; on the ASCII chart. No secondary weight comparison is performed.

In the second example, &quot;Aaa&quot; is less than &quot;aaa&quot; following the same logic shown in the comparison of &quot;A&quot; and &quot;a&quot;.

When two characters are compared and they are equal, this is called a &quot;collision,&quot; and &quot;delayed comparison&quot; 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<F = -1

RESOLUTION
If you need to sort by ASCII values using case sensitivity, use the C run-time function strcmp or _fstrcmp.

Also, Far East Windows-based applications adopt this dictionary sorting technique in English and local languages.

For detailed information about the sort order used with non-alphabetic characters, accented characters, and characters in international languages, query on the following words in this Knowledge Base:

"lstrcmpi and international and sort" Additional query words: 3.00 3.10 lstrcmpi strcmpi

Keywords :

Issue type :

Technology : kbAudDeveloper kbWin3xSearch kbSDKSearch kbWinSDKSearch kbWinSDK300 kbWinSDK310