Function Reference


Compares two character strings for a specified locale

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


$iLCID The locale identifier (LCID) that specifies the locale or one of the following predefined values:
Windows Vista or later
$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:



Windows 7 or later

Return Value

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


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

See Also

Search CompareString in MSDN Library.


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

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

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

_ArrayDisplay($aItem, 'Initial array')

; Simple array sorting

_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


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