Sign in to follow this  
Followers 0
dianaManolito

String Comparison

4 posts in this topic

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

Share this post


Link to post
Share on other sites



Well you couls make your own sort function :whistle: Split the string and compare as you descripe :)


Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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.

Share this post


Link to post
Share on other sites

Thanks Larry, your example is a common sense one , but i still don't like the following AUTOIT sorting :

-

1

-1

??

Share this post


Link to post
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
Sign in to follow this  
Followers 0