Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

National word-sorting according to locale setting using "lstrcmp" and "lstrcmpi"

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • National word-sorting according to locale setting using "lstrcmp" and "lstrcmpi"

    ' National word-sorting according to locale setting using "lstrcmp" and "lstrcmpi".

    ' The locale setting determines how your national language is supported in Windows.
    ' It is defined by locale identifiers, LCTYPE constants, country codes, and language
    ' identifiers.

    ' A locale identifier (LCID) is a DWORD value containing the language identifier in
    ' the lower word and a reserved value in the upper word. The identifier supplied in
    ' an LCID is a standard international numeric abbreviation. This LCID has the components
    ' necessary to uniquely identify one of the installed system-defined locales.
    ' Applications can use the MAKELCID macro to create LCID values. There are two predefined
    ' LCID values: LOCALE_SYSTEM_DEFAULT is the system default locale, and LOCALE_USER_DEFAULT
    ' is the current user's locale.

    ' Comparison of strings based on the current user locale can be made using "lstrcmp", which
    ' is case-sensitive, and "lstrcmpi", which is case-insensitive. However, the case-sensivity
    ' seems to be working only for English characters.

    ' Typically, strings are compared using what is called a "word sort" technique.
    ' In a word sort, all punctuation marks and other nonalphanumeric characters, except for
    ' the hyphen and the apostrophe, come before any alphanumeric character.
    ' The hyphen and the apostrophe are treated differently than the other nonalphanumeric
    ' symbols, in order to ensure that words such as "coop" and "co-op" stay together within
    ' a sorted list.
    '
    ' Best regards,
    '
    ' Erik

    Code:
    #COMPILE EXE
    #REGISTER NONE
    #DIM ALL
    
    #INCLUDE "win32api.inc"
    
    FUNCTION PBMAIN
        LOCAL no AS LONG
        No = 9
        DIM wds(1 TO no) AS ASCIIZ * 20  ' the words to sort
        DIM i AS LONG, j AS LONG
        DIM s AS STRING
        DIM t AS STRING
        '
        ' Load the strings into the array.
        s = "Name"       : wds(1) =  s
        s = "name"       : wds(2) =  s
        s = "Ærø"       : wds(3) =  s
        s = "Ært"       : wds(4) =  s
        s = "Øresund"   : wds(5) =  s
        s = "År"    : wds(6) =  s
        s = "åre"       : wds(7) =  s
        s = "æble"      : wds(8) =  s
        s = "øre"       : wds(9) =  s
        '
        t = "Case-insensitive sorting" + $CRLF
        ' Sort the strings, swapping any pairs which are out of order.
        FOR i = 1 TO no - 1         ' first string of the pair
            FOR j = i + 1 TO no     ' second string of the pair
                ' Compare the two strings.
                ' If wds(i) is greater, then swap them.
                IF lstrcmpi(wds(i), wds(j)) > 0 THEN SWAP wds(i), wds(j)
            NEXT j
        NEXT i
        '
        FOR i = 1 TO no
            t = t + wds(i) + $CRLF
        NEXT i
        t = t + $CRLF
        t = t + "Case-sensitive sorting" + $CRLF
        ' Sort the strings, swapping any pairs which are out of order.
        FOR i = 1 TO no - 1         ' first string of the pair
            FOR j = i + 1 TO no     ' second string of the pair
                ' Compare the two strings.
                ' If wds(i) is greater, then swap them.
                IF lstrcmp(wds(i), wds(j)) > 0 THEN SWAP wds(i), wds(j)
            NEXT j
        NEXT i
    
        FOR i = 1 TO no
            t = t + wds(i) + $CRLF
        NEXT i
    
        MSGBOX t,,"Word-sorting"
    
    END FUNCTION
    ------------------


    [This message has been edited by Erik Christensen (edited July 08, 2004).]
Working...
X