Sign in to follow this  
Followers 0
AGlassman

_ArraySort - Non-ASCII order for "^"?

2 posts in this topic

I was under the assumtion that _ArraySort sorted in ASCII order, so I can not explain the following:

CODE

#include <Array.au3>

Dim $a[5] = ["z" , "!" , "#" , "+" , "^" ]

_ArrayDisplay( $a )

_ArraySort( $a )

_ArrayDisplay( $a )

Which, after the _ArraySort outputs:

[0]|!

[1]|#

[2]|^

[3]|+

[4]|z

But the "^" seems out of place since ASC("#")=35, ASC("^")=94, and ASC("+")=43. I've tried wrapping the values in String(), using multi-char strings, etc. But the "^" keeps sorting out ahead of the "+". I'm using a sorted array that contains "^..." strings in an _ArrayBinarySearch and I'm concerned that it might start failing in the future since the sort order doesn't appear correct.

I'm certain it's something I don't understand about AutoIt, but any explanation or advice would be appreciated.

AutoIt v3.2.10.0, XP SP2.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Advice - use this http://www.autoitscript.com/forum/index.php?showtopic=63525 if you want consistent and logical results (not to mention the speed). Although I've noticed it's not fully compatible with AutoIt's string compare - there is issue with underscore (_ < 0, but 1_ > 10) which could be fixed by replacing strcmp/_strcmpi with kernel's lstrcmp/lstrcmpi, but I never cared that much to do it.

Bottom line is, if you expect trouble using _ArrayBinarySearch on these chars, then test it, do not assume things like you do now. Are you really sure it will be an issue? In theory both _ArrayBinarySearch and _ArraySort use the same string comparison, so even if the sort order doesn't look very logical, it should match.

Edited by Siao

"be smart, drink your wine"

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