现在的位置: 首页 > 综合 > 正文

lstrcmp Function

2014年03月08日 ⁄ 综合 ⁄ 共 2214字 ⁄ 字号 评论关闭

lstrcmp Function


Compares two character strings. The comparison is case-sensitive.

To perform a comparison that is not case-sensitive, use the lstrcmpi function.

 

Syntax

int lstrcmp(      

    LPCTSTR lpString1,     LPCTSTR lpString2 );

Parameters

lpString1
[in] Pointer to the first null-terminated string to be compared.
lpString2
[in] Pointer to the second null-terminated string to be compared.

Return Value

If the string pointed to by lpString1 is less than the string pointed to by lpString2, the return value is negative. If the string pointed to by lpString1 is greater than the string pointed to by lpString2, the return value is positive. If the strings are equal, the return value is zero.

Remarks

The lstrcmp function compares two strings by checking the first characters against each other, the second characters against each other, and so on until it finds an inequality or reaches the ends of the strings.

Note that the lpString1 and lpString2 parameters must be null-terminated, otherwise the string comparison can be incorrect.

The function calls CompareString, using the current thread locale, and subtracts 2 from the result, to maintain the C run-time conventions for comparing strings.

The language (user locale) selected by the user at setup time, or through Control Panel, determines which string is greater (or whether the strings are the same). If no language (user locale) is selected, the system performs the comparison by using default values.

With a double-byte character set (DBCS) version of the system, this function can compare two DBCS strings.

The lstrcmp function uses a word sort, rather than a string sort. A word sort treats hyphens and apostrophes differently than it treats other symbols that are not alphanumeric, in order to ensure that words such as "coop" and "co-op" stay together within a sorted list. For a detailed discussion of word sorts and string sorts, see the Remarks section for the CompareString function.

Windows 95/98/Me: lstrcmpW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems World Wide Web link.

Example

For an example, see Determining the Location of a Share.

Function Information

Minimum DLL Version kernel32.dll
Header Declared in Winbase.h, include Windows.h
Import library Kernel32.lib
Minimum operating systems Windows 95, Windows NT 3.1
Unicode Implemented as ANSI and Unicode versions.

See Also

Strings Overview, Collation, CompareString, CompareStringEx, CompareStringOrdinal, lstrcat, lstrcmpi, lstrcpy, lstrlen


抱歉!评论已关闭.