网站首页  词典首页

请输入您要查询的函数:

 

术语 comparestring
释义 CompareString
语法:
int CompareString(
__in LCID Locale,
__in DWORD dwCmpFlags,
__in LPCTSTR lpString1,
__in int cchCount1,
__in LPCTSTR lpString2,
__in int cchCount2
);
CompareString功能
比较两个字符串,由标识符指定的语言环境。
Caution Using CompareString incorrectly can compromise the security of your application.字符串不正确的比较,可以产生无效的输入。例如,函数可以提高使用时的非语言的比较,因为两个字符串都是以二进制表示不同的语言等同,可安全问题。应该测试应用程序的有效性在使用它们之前的字符串,并应提供错误处理。有关更多信息,请参阅安全注意事项:国际特色。
注意:对于Unicode的兼容性,您的应用程序应该喜欢CompareStringEx或CompareString Unicode版本。宁愿CompareStringEx另一个原因是,微软正在朝着新的,而不是区域设置的区域设置标识符迁移地区名称的使用,互操作性的原因。任何将只运行在Windows Vista和以后应使用CompareStringEx申请。
参数
区域设置 [in]
区域设置标识符为比较使用的语言环境。您可以使用MAKELCID宏创建一个区域设置标识符或使用下列预定义的值之一。
LOCALE_CUSTOM_DEFAULT
LOCALE_CUSTOM_UI_DEFAULT
LOCALE_CUSTOM_UNSPECIFIED
LOCALE_INVARIANT
LOCALE_SYSTEM_DEFAULT
LOCALE_USER_DEFAULT
dwCmpFlags [in]
标志,指示函数如何比较两个字符串。默认情况下,这些标志都没有设置。此参数可以指定下列值的任意组合,也可以设置为0,以获取默认行为。
FlagMeaning
LINGUISTIC_IGNORECASEIgnore情况下,适当的语言。
LINGUISTIC_IGNOREDIACRITICIgnore nonspacing字符,语言恰当的。
注意:此标志并不总是产生预期的效果时使用的字符分解,即字符,其中一个基本字符和一个或多个nonspacing字符各有不同的码点值。
NORM_IGNORECASEIgnore情况。对于(特别是拉丁语系)许多脚本,NORM_IGNORECASE恰逢LINGUISTIC_IGNORECASE。
注意NORM_IGNORECASE忽略任何高等教育的区别,无论是语言的情况,其实不是。例如,在阿拉伯语和印度语文字,这有别于其他的字符形式,但差异不符合语言的情况。 LINGUISTIC_IGNORECASE导致函数忽略实际语言只是外壳,而不是无视第三排序的重量。
注意:在设置了这个标志,函数忽略了中日韩之间的兼容性字符宽与窄形式的区别。
NORM_IGNOREKANATYPEDo不区分平假名和片假名字符。相应的平假名和片假名字符比较平等。
NORM_IGNORENONSPACEIgnore nonspacing字符。对于(特别是拉丁语系)许多脚本,NORM_IGNORENONSPACE恰逢LINGUISTIC_IGNOREDIACRITIC。
注意NORM_IGNORENONSPACE忽略任何次要的区别,无论是读音符号与否。韩国,日本,中国和印度语言脚本,除其他外,用于其他目的而变音符号这种区别。 LINGUISTIC_IGNOREDIACRITIC导致函数忽略只有实际发音符号,而不是无视第二排序的重量。
注意NORM_IGNORENONSPACE只有在其中的一个重音字符是从第二阶段的主要特征排序语言环境的影响。通常在字符串中的所有字符都首先比较不考虑口音,如果字符串相等,比第二阶段是字符串进行比较的口音。此标志将导致第二阶段不被执行。对于语言环境,在第一个通过排序重音字符,该标志无效。
NORM_IGNORESYMBOLSIgnore符号和标点符号。
NORM_IGNOREWIDTHIgnore例如之间的半宽度和全角字符的差异,C的==猫。全宽形式是格式区分中文和日文脚本。
NORM_LINGUISTIC_CASINGUse语言规则的外壳,而不是文件系统的规则(默认)。
SORT_DIGITSASNUMBERSWindows 7:治疗期间,以数字排序数字,例如,类似“2”之前的“10”。
SORT_STRINGSORTTreat标点符号作为符号相同。
lpString1 [in]
指向一个字符串进行比较。
cchCount1 [in]
字符串的长度由lpString1表示,不包括终止空字符。此值代表了广泛的职能和角色的ANSI Unicode版本的版本字节。应用程序可以提供一个负值,如果字符串是空终止。在这种情况下,函数的长度自动确定。
lpString2 [in]
指向第二个字符串进行比较。
cchCount2 [in]
字符串的长度由lpString2表示,不包括终止空字符。此值代表了广泛的职能和角色的ANSI Unicode版本的版本字节。应用程序可以提供一个负值,如果字符串是空终止。在这种情况下,函数的长度自动确定。
返回值
返回下列值之一,如果成功。为了保持比较字符串C运行时约定,值2可以减去一个非零的返回值。然后,“0的意义,== 0,和”> 0是符合C运行。
CSTR_LESS_THAN。该字符串lpString1指出的是词汇的价值低于字符串lpString2表示。
CSTR_EQUAL。该字符串lpString1表示在词法价值相当于所显示的字符串lpString2。这两个字符串相当于排序的目的,但并不一定完全相同。
CSTR_GREATER_THAN。该字符串lpString1表示更大的词汇值大于字符串lpString2表示。
该函数返回0,如果没有成功。为了获得更多错误信息,应用程序可以调用GetLastError函数,可以返回以下错误代码之一:
ERROR_INVALID_FLAGS。旗帜提供的值无效。
ERROR_INVALID_PARAMETER。该参数值的任何无效。
备注
双方CompareString和CompareStringEx优化运行的最高速度,当dwCmpFlags设置为0或NORM_IGNORECASE,cchCount1和cchCount2被设置为-1,区域不支持任何语言的压缩,因为在传统的西班牙分类对待“通道”为单个字符。
如果应用程序调用的CompareString ANSI版本,功能转换通过所提供的语言环境的默认代码页参数。因此,应用程序不能使用CompareString来处理UTF - 8文本。
通常来说,不区分大小写的比较,CompareString地图小写的“i”的大写的“I”,即使语言环境是土耳其或阿塞拜疆。国旗覆盖的NORM_LINGUISTIC_CASING此行为土耳其和阿塞拜疆。如果此标志是与土耳其和阿塞拜疆,拉丁文小写字母不带点I(ü 0131)是拉丁语大写字母我小写形式(ü 0049)和拉丁美洲小额信中,我(ü 0069)一起指定的小写形式拉美资本与运输部以上(ü 0130)信我。
双方CompareString和CompareStringEx忽略了比较阿拉伯语kashidas。因此,如果两个字符串除了在场的kashidas相同,则函数返回CSTR_EQUAL。
当应用程序使用排序功能NORM_IGNORENONSPACE和NORM_IGNORECASE旗帜,标志,有时干扰字符串比较。这种情况可能会导致某个区域,不支持非空格字符或个案,但使用相同重量的Level,以处理其他重要的行动。在这种情况下,您的应用程序应该使用LINGUISTIC_IGNOREDIACRITIC和LINGUISTIC_IGNORECASE标志。这些标志提供的排序代码点用例和读音符号的商标,并没有对其他语言代码点的影响适当的结果。
Windows Vista和更高版本:无论CompareString和CompareStringEx可以从自定义区域设置的数据。数据不能保证从同一计算机到计算机之间或应用程序的运行。如果应用程序必须坚持或传输数据,请参阅使用持久性本地化数据。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinnls.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode和ANSI namesCompareStringW(Unicode)和CompareStringA(ANSI)的
参见
国家语言支持
国家语言支持功能
在应用程序中处理排序
使用Unicode正常化表示字符串
安全注意事项:国际特色
CompareStringEx
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年7月12号
==英文原文==CompareString Function
Compares two character strings, for a locale specified by identifier.
Caution Using CompareString incorrectly can compromise the security of your application. Strings that are not compared correctly can produce invalid input. For example, the function can raise security issues when used for a non-linguistic comparison, because two strings that are distinct in their binary representation can be linguistically equivalent. The application should test strings for validity before using them, and should provide error handlers. For more information, see Security Considerations: International Features .
Note For compatibility with Unicode, your applications should prefer CompareStringEx or the Unicode version of CompareString. Another reason for preferring CompareStringEx is that Microsoft is migrating toward the use of locale names instead of locale identifiers for new locales, for interoperability reasons. Any application that will be run only on Windows Vista and later should use CompareStringEx .
Syntax
int CompareString(
__in LCID Locale,
__in DWORD dwCmpFlags,
__in LPCTSTR lpString1,
__in int cchCount1,
__in LPCTSTR lpString2,
__in int cchCount2
);
Parameters
Locale [in]
Locale identifier of the locale used for the comparison. You can use the MAKELCID macro to create a locale identifier or use one of the following predefined values.
LOCALE_CUSTOM_DEFAULT
LOCALE_CUSTOM_UI_DEFAULT
LOCALE_CUSTOM_UNSPECIFIED
LOCALE_INVARIANT
LOCALE_SYSTEM_DEFAULT
LOCALE_USER_DEFAULT
dwCmpFlags [in]
Flags that indicate how the function compares the two strings. By default, these flags are not set. This parameter can specify a combination of any of the following values, or it can be set to 0 to obtain the default behavior.
FlagMeaning
LINGUISTIC_IGNORECASEIgnore case, as linguistically appropriate.
LINGUISTIC_IGNOREDIACRITICIgnore nonspacing characters, as linguistically appropriate.
Note This flag does not always produce predictable results when used with decomposed characters, that is, characters in which a base character and one or more nonspacing characters each have distinct code point values.
NORM_IGNORECASEIgnore case. For many scripts (notably Latin scripts), NORM_IGNORECASE coincides with LINGUISTIC_IGNORECASE.
Note NORM_IGNORECASE ignores any tertiary distinction, whether it is actually linguistic case or not. For example, in Arabic and Indic scripts, this distinguishes alternate forms of a character, but the differences do not correspond to linguistic case. LINGUISTIC_IGNORECASE causes the function to ignore only actual linguistic casing, instead of ignoring the third sorting weight.
Note With this flag set, the function ignores the distinction between the wide and narrow forms of the CJK compatibility characters.
NORM_IGNOREKANATYPEDo not differentiate between hiragana and katakana characters. Corresponding hiragana and katakana characters compare as equal.
NORM_IGNORENONSPACEIgnore nonspacing characters. For many scripts (notably Latin scripts), NORM_IGNORENONSPACE coincides with LINGUISTIC_IGNOREDIACRITIC.
Note NORM_IGNORENONSPACE ignores any secondary distinction, whether it is a diacritic or not. Scripts for Korean, Japanese, Chinese, and Indic languages, among others, use this distinction for purposes other than diacritics. LINGUISTIC_IGNOREDIACRITIC causes the function to ignore only actual diacritics, instead of ignoring the second sorting weight.
Note NORM_IGNORENONSPACE only has an effect for locales in which accented characters are sorted in a second pass from main characters. Normally all characters in the string are first compared without regard to accents and, if the strings are equal, a second pass over the strings is performed to compare accents. This flag causes the second pass to not be performed. For locales that sort accented characters in the first pass, this flag has no effect.
NORM_IGNORESYMBOLSIgnore symbols and punctuation.
NORM_IGNOREWIDTHIgnore the difference between half-width and full-width characters, for example, C a t == cat. The full-width form is a formatting distinction used in Chinese and Japanese scripts.
NORM_LINGUISTIC_CASINGUse linguistic rules for casing, instead of file system rules (default).
SORT_DIGITSASNUMBERSWindows 7: Treat digits as numbers during sorting, for example, sort "2" before "10".
SORT_STRINGSORTTreat punctuation the same as symbols.

lpString1 [in]
Pointer to the first string to compare.
cchCount1 [in]
Length of the string indicated by lpString1, excluding the terminating null character. This value represents bytes for the ANSI version of the function and wide characters for the Unicode version. The application can supply a negative value if the string is null-terminated. In this case, the function determines the length automatically.
lpString2 [in]
Pointer to the second string to compare.
cchCount2 [in]
Length of the string indicated by lpString2, excluding the terminating null character. This value represents bytes for the ANSI version of the function and wide characters for the Unicode version. The application can supply a negative value if the string is null-terminated. In this case, the function determines the length automatically.
Return Value
Returns one of the following values if successful. To maintain the C runtime convention of comparing strings, the value 2 can be subtracted from a nonzero return value. Then, the meaning of <0, ==0, and >0 is consistent with the C runtime.
CSTR_LESS_THAN. The string indicated by lpString1 is less in lexical value than the string indicated by lpString2.
CSTR_EQUAL. The string indicated by lpString1 is equivalent in lexical value to the string indicated by lpString2. The two strings are equivalent for sorting purposes, although not necessarily identical.
CSTR_GREATER_THAN. The string indicated by lpString1 is greater in lexical value than the string indicated by lpString2.
The function returns 0 if it does not succeed. To get extended error information, the application can call GetLastError , which can return one of the following error codes:
ERROR_INVALID_FLAGS. The values supplied for flags were invalid.
ERROR_INVALID_PARAMETER. Any of the parameter values was invalid.
Remarks
Both CompareString and CompareStringEx are optimized to run at the highest speed when dwCmpFlags is set to 0 or NORM_IGNORECASE, cchCount1 and cchCount2 are set to -1, and the locale does not support any linguistic compressions, as when traditional Spanish sorting treats "ch" as a single character.
If your application is calling the ANSI version of CompareString, the function converts parameters via the default code page of the supplied locale. Thus, an application can never use CompareString to handle UTF-8 text.
Normally, for case-insensitive comparisons, CompareString maps the lowercase "i" to the uppercase "I", even when the locale is Turkish or Azeri. The NORM_LINGUISTIC_CASING flag overrides this behavior for Turkish or Azeri. If this flag is specified in conjunction with Turkish or Azeri, LATIN SMALL LETTER DOTLESS I (U+0131) is the lowercase form of LATIN CAPITAL LETTER I (U+0049) and LATIN SMALL LETTER I (U+0069) is the lowercase form of LATIN CAPITAL LETTER I WITH DOT ABOVE (U+0130).
Both CompareString and CompareStringEx ignore Arabic kashidas during the comparison. Thus, if two strings are identical except for the presence of kashidas, the function returns CSTR_EQUAL.
When the application uses the NORM_IGNORENONSPACE and NORM_IGNORECASE flags with the sorting function, the flags can sometimes interfere with string comparisons. This situation might result for a locale that does not support non-spacing characters or case, but uses equivalent weight levels to handle other important operations. In such cases, your application should use the LINGUISTIC_IGNOREDIACRITIC and LINGUISTIC_IGNORECASE flags. These flags provide linguistically appropriate results for sorting code points that use case and diacritic marks, and have no impact on other code points.
Windows Vista and later: Both CompareString and CompareStringEx can retrieve data from custom locales . Data is not guaranteed to be the same from computer to computer or between runs of an application. If your application must persist or transmit data, see Using Persistent Locale Data .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinnls.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode and ANSI namesCompareStringW (Unicode) and CompareStringA (ANSI)
See Also
National Language Support
National Language Support Functions
Handling Sorting in Your Applications
Using Unicode Normalization to Represent Strings
Security Considerations: International Features
CompareStringEx
Send comments about this topic to Microsoft
Build date: 7/12/2009
==原始网址==http://msdn.microsoft.com/en-us/library/dd317759(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 11:29:14