String.Compare lesser or greater than explanation

  1. 5 weeks ago

    Arthur G

    Jun 1 Testers, Xojo Pro
    Edited 5 weeks ago

    I went looking through my code and ran across the String.Compare function.
    It has 3 responses;
    0 if the two are equal.

    The other two weren't clear.

    Returns a negative integer if the value is less than other, 0 if the two values are equal, and a positive integer if the value is greater than other.

    Someone posted this "zeus" "suez" and it apparently got some response from this compare.

    Is there a better definition than the example in the LR, because apparently the dog, or is it the cat, is greater?

    Var dog As String = "Dog"
    Var cat As String = "Cat"
    
    Var result As Integer
    result = dog.Compare(cat)
    
    // result > 0

    One obvious use case would be within your own CompareRows event handler for a listbox.

  2. Norman P

    Jun 1 Testers, Xojo Pro outside admiring the sunshine,...

    lexically Dog is > Cat (Dog would be after Cat the dictionary) when compared case insensitively

  3. Arthur G

    Jun 1 Testers, Xojo Pro

    Thanks. I was thinking that would be the way. Lexical isn't what I was hoping for.

  4. Norman P

    Jun 1 Testers, Xojo Pro outside admiring the sunshine,...

    thats just the default with the way its used in that code you posted
    There are other mode as well
    see http://docs.xojo.com/String.Compare

  5. Arthur G

    Jun 1 Testers, Xojo Pro

    Do you ever have a use for this?

  6. Norman P

    Jun 1 Testers, Xojo Pro outside admiring the sunshine,...

    sometimes
    not a lot though

  7. Douglas H

    Jun 1 Testers, Xojo Pro Answer

    One obvious use case would be within your own CompareRows event handler for a listbox.

or Sign Up to reply!