please dont rip this site Prev Next

CompareString info  Overview  Group

The CompareString function compares two character strings, using the locale specified by the given identifier as the basis for the comparison.

int CompareString(

    LCID Locale,

// locale identifier

    DWORD dwCmpFlags,

// comparison-style options

    LPCTSTR lpString1,

// pointer to first string

    int cchCount1,

// size, in bytes or characters, of first string

    LPCTSTR lpString2,

// pointer to second string

    int cchCount2 

// size, in bytes or characters, of second string

   );

Parameters

Locale
Specifies the locale used for the comparison. This parameter can be one of the following predefined locale identifiers:

Value

Meaning

LOCALE_SYSTEM_DEFAULT

The system’s default locale.

LOCALE_USER_DEFAULT

The current user’s default locale.

This parameter can also be a locale identifier created by the MAKELCID macro.

dwCmpFlags
A set of flags that indicate how the function compares the two strings. By default, these flags are not set. This parameter can specify zero to get the default behavior, or it can be any combination of the following values:

Value

Meaning

NORM_IGNORECASE

Ignore case.

NORM_IGNOREKANATYPE

Do not differentiate between Hiragana and Katakana characters. Corresponding Hiragana and Katakana characters compare as equal.

NORM_IGNORENONSPACE

Ignore nonspacing characters.

NORM_IGNORESYMBOLS

Ignore symbols.

NORM_IGNOREWIDTH

Do not differentiate between a single-byte character and the same character as a double-byte character.

SORT_STRINGSORT

Treat punctuation the same as symbols.

lpString1
Points to the first string to be compared.
cchCount1
Specifies the size, in bytes (ANSI version) or characters (Unicode version), of the string pointed to by the lpString1 parameter. If this parameter is - 1, the string is assumed to be null terminated and the length is calculated automatically.
lpString2
Points to the second string to be compared.
cchCount2
Specifies the size, in bytes (ANSI version) or characters (Unicode version), of the string pointed to by the lpString2 parameter. If this parameter is - 1, the string is assumed to be null terminated and the length is calculated automatically.

Return Values

If the function succeeds, the return value is one of the following values:

Value

Meaning

CSTR_LESS_THAN

The string pointed to by the lpString1 parameter is less in lexical value than the string pointed to by the lpString2 parameter.

CSTR_EQUAL

The string pointed to by lpString1 is equal in lexical value to the string pointed to by lpString2.

CSTR_GREATER_THAN

The string pointed to by lpString1 is greater in lexical value than the string pointed to by lpString2.

If the function fails, the return value is zero. To get extended error information, call GetLastError. GetLastError may return one of the following error codes:

ERROR_INVALID_FLAGS

ERROR_INVALID_PARAMETER

Remarks

Notice that if the return value is 2, the two strings are “equal” in the collation sense, though not necessarily identical.

To maintain the C run-time convention of comparing strings, the value 2 can be subtracted from a nonzero return value. The meaning of < 0, ==0 and > 0 is then consistent with the C run times.

If the two strings are of different lengths, they are compared up to the length of the shortest one. If they are equal to that point, then the return value will indicate that the longer string is greater. For more information about locale identifiers, see Locale Identifiers.

Typically, strings are compared using what is called a “word sort” technique. In a word sort, all punctuation marks and other nonalphanumeric characters, except for the hyphen and the apostrophe, come before any alphanumeric character. The hyphen and the apostrophe are treated differently than the other nonalphanumeric symbols, in order to ensure that words such as “coop” and “co-op” stay together within a sorted list.

If the SORT_STRINGSORT flag is specified, strings are compared using what is called a “string sort” technique. In a string sort, the hyphen and apostrophe are treated just like any other nonalphanumeric symbols: they come before the alphanumeric symbols.

The following table shows a list of words sorted both ways:

Word Sort

String Sort

     

Word Sort

String Sort

billet

bill’s

 

t-ant

t-ant

bills

billet

 

tanya

t-aria

bill’s

bills

 

t-aria

tanya

cannot

can’t

 

sued

sue’s

cant

cannot

 

sues

sued

can’t

cant

 

sue’s

sues

con

co-op

 

went

we’re

coop

con

 

were

went

co-op

coop

 

we’re

were

The lstrcmp and lstrcmpi functions use a word sort. The CompareString and LCMapString functions default to using a word sort, but use a string sort if their caller sets the SORT_STRINGSORT flag.

The CompareString function is optimized to run at the highest speed when dwCmpFlags is set to 0 or NORM_IGNORECASE, and cchCount1 and cchCount2 have the value -1.

The CompareString function ignores Arabic Kashidas during the comparison. Thus, if two strings are identical save for the presence of Kashidas, CompareString returns a value of 2; the strings are considered "equal" in the collation sense, though they are not necessarily identical.

See Also

FoldString, GetSystemDefaultLCID, GetUserDefaultLCID, LCMapString, lstrcmp, lstrcmpi, MAKELCID 


file: /Techref/os/win/api/win32/func/src/f06_16.htm, 13KB, , updated: 2000/4/7 11:19, local time: 2024/11/24 04:00,
TOP NEW HELP FIND: 
3.138.125.86:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://techref.massmind.org/techref/os/win/api/win32/func/src/f06_16.htm"> CompareString</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to techref.massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .