The Locale Explorer: CompareString |
|
One of several comparison operators can be chosen. The results will be quite different depending on the comparison mechanism chosen. The CompareString API is the most general and locale-aware. However, the options for _tcscmp, _tcsicmp,lstrcmp, and lstrcmpi are all selectable. Whenever these calls are used, the thread locale that is set will be the thread locale selected, so the runtime libraries are using the same parameters that you would expect to have used by a program running in that locale. For example, the code that implements _tcscmp is equivalent to that shown below (some details have been omitted since they are irrelevant to this discussion, such as the fact that the locale is actually set outside the loop to avoid a lot of APIs going on inside the loop).
LCID oldlcid = ::GetThreadLocale(); //**************************************************************** // _tcscmp //**************************************************************** if(c_UseTcsCmp.GetCheck() == BST_CHECKED) { /* tcscmp */ ::SetThreadlocale(lcid); int result = _tcscmp(p1, p2); ::SetThreadLocale(oldlcid); return result; } /* tcscmp */
Notice that this screen resembles the LCMapString page. This is not coincidence; the CLCMapString screen is a derived class of the CCompareString class.
Here are several comparisons
CompareString U.S. English, no flags |
CompareString NORM_IGNORENONSPACE |
_tcscmp | _tcsicmp | lstrcmp | lstrcmpi |
Note that there is no apparent difference between lstrcmp and lstrcmpi.
The views expressed in these essays are those of the author, and in no way represent, nor are they endorsed by, Microsoft.