;---------------------------------------------------------------------------------------------------------------------- ; Function _ArraySortByLen(ByRef $ARRAY [, $iDESCENDING=0 [, $iDIM=0[ , $iSORT=0]]]) ; ; Description - Sorts an 1D/2D Array by Length. ; - BaseIndex is 0; sorts the whole array. ; ; Parameter $ARRAY: Array to sort ; optional $iDESCENDING: Sort ascending[0]/descending[1] (default 0) ; optional $iDIM: Occurences in the second dimension, eg $A[100]=0 or $A[100][2]=2 (default 0) ; optional $iSORT: SortIndex by using 2 dimensions (default 0) ; ; Return ByRef sorted Array by Length ; ; Requirements Only 2 occurences in the second dimension ; #include ; ; Author BugFix (bugfix@autoit.de) ;---------------------------------------------------------------------------------------------------------------------- Func _ArraySortByLen(ByRef $ARRAY, $iDESCENDING=0, $iDIM=0, $iSORT=0) Local $arTmp1D[1][1], $arTmp2D[1][1] If $iDIM = 0 Then $iDIM = 1 Switch $iDIM Case 1 ; 1D ReDim $arTmp1D[UBound($ARRAY)][2] For $i = 0 To UBound($ARRAY)-1 $arTmp1D[$i][0] = StringLen($ARRAY[$i]) $arTmp1D[$i][1] = $ARRAY[$i] $ARRAY[$i] = '' Next _ArraySort($arTmp1D,$iDESCENDING,0,0,2,0) For $i = 0 To UBound($arTmp1D)-1 $ARRAY[$i] = $arTmp1D[$i][1] Next Case 2 ; 2D ReDim $arTmp2D[UBound($ARRAY)][3] For $i = 0 To UBound($ARRAY)-1 $arTmp2D[$i][2] = StringLen($ARRAY[$i][$iSORT]) $arTmp2D[$i][0] = $ARRAY[$i][0] $arTmp2D[$i][1] = $ARRAY[$i][1] $ARRAY[$i][0] = '' $ARRAY[$i][1] = '' Next _ArraySort($arTmp2D,$iDESCENDING,0,0,3,2) For $i = 0 To UBound($arTmp2D)-1 $ARRAY[$i][0] = $arTmp2D[$i][0] $ARRAY[$i][1] = $arTmp2D[$i][1] Next EndSwitch EndFunc ; ==>_ArraySortByLen