Jump to content

Recommended Posts

Posted (edited)

Code is simple/selfexplanatory ...

 

#include "Array.au3"

$a = StringSplit('aaa,b,cc', ',', 2) ; no_count
_ArraySortLen($a)
_ArrayDisplay($a, '$a - without count')

$b = StringSplit('aaa,b,cc', ',')
_ArraySortLen1($b)
_ArrayDisplay($b, '$b - with count')

; zero based array (without count at [0])
Func _ArraySortLen(ByRef $aArr, $iDescending = 0)
    Local $j = UBound($aArr)-1
    Local $aTemp[$j+1][2]
    For $i = 0 To $j
        $aTemp[$i][0] = StringLen($aArr[$i])
        $aTemp[$i][1] = $aArr[$i]
    Next
    _ArraySort($aTemp,$iDescending)
    For $i = 0 To $j
        $aArr[$i] = $aTemp[$i][1]
    Next
EndFunc

; one based array (with count at [0])
Func _ArraySortLen1(ByRef $aArr, $iDescending = 0)
    Local $j = $aArr[0]
    Local $aTemp[$j+1][2]
    For $i = 1 To $j
        $aTemp[$i][0] = StringLen($aArr[$i])
        $aTemp[$i][1] = $aArr[$i]
    Next
    _ArraySort($aTemp,$iDescending,1)
    For $i = 1 To $j
        $aArr[$i] = $aTemp[$i][1]
    Next
EndFunc

 

Edited by Zedna

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
×
×
  • Create New...