Funktionreferenz


_WinAPI_CompareString


Compares two character strings for a specified locale

#include <WinAPILocale.au3>
_WinAPI_CompareString ( $iLCID, $sString1, $sString2 [, $iFlags = 0] )

Parameter

$iLCID 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 [optional] 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

Rückgabewert

Success: The one of the following values that indicates a result of the comparison strings.
    $CSTR_LESS_THAN
    $CSTR_EQUAL
    $CSTR_GREATER_THAN
Failure: 0, call _WinAPI_GetLastError() to get extended error information.

Bemerkungen

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).

Siehe auch

Suche nach CompareString in der MSDN Bibliothek.

Beispiel

#include <APILocaleConstants.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <WinAPILocale.au3>
#include <WinAPISys.au3>

If Number(_WinAPI_GetVersion()) < 6.1 Then
    MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Error', 'Require Windows 7 or later.')
    Exit
EndIf

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

_ArrayDisplay($aItem, 'Initial array')

; Simple array sorting
_ArraySort($aItem)

_ArrayDisplay($aItem, 'Simple sorting')

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

        EndSwitch
    Next
Next

_ArrayDisplay($aItem, 'bubble sort case insensitive')