Jump to content
Sign in to follow this  
topten

Need help with _ArraySort

Recommended Posts

topten

I have some data of numbers  $mydata = "10,2000,300,400,500,550" I asign it into array via regexp, then I sort it with _arraysort and as the result I get that 550 is the biggest number here! What am I doing wrong?

Result of console write is

550
500
400
300
2000
10

#include <array.au3>
Global $arr[6]
$mydata = "10,2000,300,400,500,550"
$array1 = StringRegExp($mydata, '(\d+)', 3)
 for $i = 0 to UBound ($array1)-1
    $arr[$i] = $array1[$i]


 next
_ArraySort($arr,1)

 for $z = 0 to UBound ($arr)-1

 ConsoleWrite ($arr[$z]&@CRLF)

 next

Share this post


Link to post
Share on other sites
SmOke_N

You're sorting a "string" (thus StringRegExp), so it sorts based on that char 1 vs char 2 etc.  You're also sorting descending, you need to sort ascending.

#include <array.au3>
$mydata = "10,2000,300,400,500,550"
$array1 = StringRegExp($mydata, '(\d+)', 3)
Global $arr[UBound($array1)]
 for $i = 0 to UBound ($array1)-1
    $arr[$i] = Int($array1[$i])
 next
_ArraySort($arr)

_ArrayDisplay($arr)

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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.