Jump to content

String Comparison


Recommended Posts

Hi !

I have a trouble with string comparison. Apparently, the following snippet returns : "yes"

if "-" < "1" then

MsgBox(1,"","yes")

ELSE

MsgBox(1,"","no")

EndIf

----------------

The second snippet returns : "no"

if "-1" < "1" then

MsgBox(1,"","yes")

ELSE

MsgBox(1,"","no")

EndIf

-----------

How is this possible if this is a string comparison. "-" (dash) has the ASCII code 45 and is smaller than the ASCII code for 1 (which is 49).

How is the sorting of strings performed? :::::

Compare the first letter=> if equal, go to next one. If the second letter is smaller(/greater), take the decision. Or is some other method used?

ex: The database "ORDER BY " clause seems to have this behavior.

Can you help me with this? How can i force the AUTOit to compare each character separately?

Thanks,

Manolito

Link to comment
Share on other sites

  • Moderators

Strings are not numbers. They aren't converted to ASCII code values without you specifically telling them to do so. So your < or > attempt is not on the specific characters on the string but the actual "string" value itself.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...