Delphi WinAPI CompareString 和 CompareStringEx 比较两个标识符指定的两个字符串函数

Delphi WinAPI CompareString 和 CompareStringEx 比较两个标识符指定的两个字符串函数

1、CompareString

函数原型:

int CompareString(
  LCID    Locale,
  DWORD   dwCmpFlags,
  LPCTSTR lpString1,
  int     cchCount1,
  LPCTSTR lpString2,
  int     cchCount2
);

参数:

  • Locale
    • LOCALE_CUSTOM_DEFAULT
    • LOCALE_CUSTOM_UI_DEFAULT
    • LOCALE_CUSTOM_UNSPECIFIED
    • LOCALE_INVARIANT
    • LOCALE_SYSTEM_DEFAULT
    • LOCALE_USER_DEFAULT
  • dwCmpFlags  //指示函数如何比较两个字符串的标志。lpString1  //指向要比较的第一个字符串的指针。
    • LINGUISTIC_IGNORECASE //忽略大小写
    • LINGUISTIC_IGNOREDIACRITIC //忽略非空字符,忽略大小写
    • NORM_IGNORECASE    // Ignore 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_IGNOREKANATYPE   //Do not differentiate between hiragana and katakana characters. Corresponding hiragana and katakana characters compare as equal.
    • NORM_IGNORENONSPACE   //Ignore 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_IGNORESYMBOLS   //Ignore symbols and punctuation.
    • NORM_IGNOREWIDTH   //Ignore 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_CASING   //Use the default linguistic rules for casing, instead of file system rules. Note that most scenarios for CompareStringEx use this flag. This flag does not have to be used when your application calls CompareStringOrdinal.
    • SORT_DIGITSASNUMBERS   //Windows 7: Treat digits as numbers during sorting, for example, sort "2" before "10".
    • SORT_STRINGSORT   //Treat punctuation the same as symbols.
  • cchCount1   //lpString1指示的字符串长度,不包括终止的空字符。
  • lpString2   //指向要比较的第二个字符串的指针。
  • cchCount2  //lpString2指示的字符串长度,不包括终止的空字符。

返回值:

  • 如果成功,则返回以下值之一。为了保持比较字符串的C运行时惯例,可以从非零返回值中减去值2。那么,<0,==0,and>0的含义与C运行时是一致的。
  • CSTR小于。lpString1指示的字符串的词法值小于lpString2指示的字符串。
  • CSTR_相等。lpString1表示的字符串在词法值上与lpString2表示的字符串等效。这两个字符串在排序时是等价的,但不一定完全相同。
  • 强制大于。lpString1指示的字符串的词法值大于lpString2指示的字符串。
  • 如果函数不成功,则返回0。

 

2、CompareStringEx

函数原型:

int CompareStringEx(
  LPCWSTR                          lpLocaleName,
  DWORD                            dwCmpFlags,
  _In_NLS_string_(cchCount1)LPCWCH lpString1,
  int                              cchCount1,
  _In_NLS_string_(cchCount2)LPCWCH lpString2,
  int                              cchCount2,
  LPNLSVERSIONINFO                 lpVersionInformation,
  LPVOID                           lpReserved,
  LPARAM                           lParam
);

  

 

 

创建时间:2020.08.27  更新时间:

 

Delphi WinAPI CompareString 和 CompareStringEx 比较两个标识符指定的两个字符串函数

上一篇:win10更换新账户,键盘在软件内使用正常但是无法在系统输入框内输入的解决方法


下一篇:AcWing245你能回答这些问题吗(线段树+逻辑思维)