函数参考


_WinAPI_CompareString

Compares two character strings for a specified locale.

#Include <WinAPIEx.au3>
_WinAPI_CompareString ( $LCID, $sString1, $sString2 [, $iFlags] )

参数

$LCID The locale identifier (LCID) that specifies the locale or one of the following predefined values.

$LOCALE_INVARIANT
$LOCALE_SYSTEM_DEFAULT
$LOCALE_USER_DEFAULT

Windows Vista or later

$LOCALE_CUSTOM_DEFAULT
$LOCALE_CUSTOM_UI_DEFAULT
$LOCALE_CUSTOM_UNSPECIFIED
$sString1 The first string to compare.
$sString2 The second string to compare.
$iFlags [可选参数] The flags that indicate how the function compares the two strings. This parameter can be 0 or
combination of the following values.

$LINGUISTIC_IGNORECASE
$LINGUISTIC_IGNOREDIACRITIC

$NORM_IGNORECASE
$NORM_IGNOREKANATYPE
$NORM_IGNORENONSPACE
$NORM_IGNORESYMBOLS
$NORM_IGNOREWIDTH
$NORM_LINGUISTIC_CASING

$SORT_STRINGSORT

Windows 7 or later

$SORT_DIGITSASNUMBERS

返回值

Success The one of the following values that indicates a result of the comparison strings.
失败: 返回 0 并设置 @error 标志为非 0 值.

注意/说明

Normally, for case-insensitive comparisons, _WinAPI_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).

相关

详情参考

在MSDN中搜索


示例/演示


#Include <APIConstants.au3>
#Include <Array.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

If _WinAPI_GetVersion() < '6.1' Then
    MsgBox(16, 'Error', 'Require Windows 7 or later.')
    Exit
EndIf

Global $Item, $Temp

; Create array of strings ("Item*")
Dim $Item[100]
For $i = 0 To UBound($Item) - 1
    $Item[$i] = 'Item' & Random(0, 100, 1)
Next

_ArrayDisplay($Item)

; Simple array sorting
_ArraySort($Item)

_ArrayDisplay($Item)

; Sort array (bubble sort) ignoring case sensitive and according to the digits
For $i = 0 To UBound($Item) - 2
    For $j = $i + 1 To UBound($Item) - 1
        Switch _WinAPI_CompareString($LOCALE_INVARIANT, $Item[$i], $Item[$j], BitOR($NORM_IGNORECASE, $SORT_DIGITSASNUMBERS))
            Case $CSTR_GREATER_THAN
                $Temp = $Item[$i]
                $Item[$i] = $Item[$j]
                $Item[$j] = $Temp
            Case Else

        EndSwitch
    Next
Next

_ArrayDisplay($Item)