Case sensitive string comparison

  1. 3 years ago

    Christian W

    29 May 2016 Pre-Release Testers Los Angeles, CA

    Hi everyone,

    I've been using Xojo for over a year and it took me until NOW to realize that string comparisons are case insensitive. I ran into a case where that broke my program's logic, and it took me several hours of hair-pulling to figure it out.

    At this point, I realize the fix is to use StrComp in mode 0 instead of = and <>, but that's going to be a HECK of a lot of work to track down all my string comparisons and manually change them (you can't just do a Find/Replace).

    Is there any way to overload the = and <> operators for strings to make them case sensitive by default? Maybe Operator_Compare? I'm not really clear based on the example provided in the docs.

    Thanks in advance!

  2. Greg O

    29 May 2016 Xojo Inc

    Not really. To use operator compare, you'd have to create your own class and use that in all cases.

  3. On the Mac I use the following snippet somebody posted ages ago:

    Function CompareRows(row1 as Integer, row2 as Integer, column as Integer, ByRef result as Integer) As Boolean
    soft declare function CFStringCompare lib "Carbon.framework" ( s1 as CFStringRef, s2 as CFStringRef, opt as UInt32 ) as integer

    dim options as UInt32 = 193//800//1 + 128 + 512 etc etc. //kCFCompareCaseInsensitive || kCFCompareDiacriticInsensitive || kCFCompareForcedOrdering etc.

    result = CFStringCompare(me.cell(row1,column), me.cell(row2,column), options )
    Return True
    End Function

    Option set to 193 makes also numbers sort correctly (against 1,11,2,3 etc.)
    Although Carbon.framework is invoked, I have not had any trouble using it in Cocoa apps or having them accepted at MAS.

    So, sorting a listbox with the following rows:
    3
    2
    1
    11
    alpha
    beta
    Ãn

    I get:
    1
    2
    3
    11
    alpha
    Ãn
    beta

or Sign Up to reply!