;---------------------------------------------------------------------------------------------------------------------- ; Function _Array2DSortByLen(ByRef $ARRAY [, $iDESCENDING=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) ; ; Return Succes -1 ByRef sorted Array by Length ; Failure 0 set @error = 1; no array ; ; Requirements Func _ArraySort_2ary() ; #include ; ; Author BugFix (bugfix@autoit.de) ;---------------------------------------------------------------------------------------------------------------------- Func _Array2DSortByLen(ByRef $ARRAY, $iDESCENDING=0) If ( Not IsArray($ARRAY) ) Then SetError(1) Return 0 EndIf If $iDESCENDING <> 0 Then $iDESCENDING = 1 Local $UBound2nd = UBound($ARRAY,2) Local $arTmp[1] = [''] If @error = 2 Then ReDim $arTmp[UBound($ARRAY)][2] For $i = 0 To UBound($ARRAY)-1 $arTmp[$i][0] = StringLen($ARRAY[$i]) $arTmp[$i][1] = $ARRAY[$i] $ARRAY[$i] = '' Next _ArraySort($arTmp,$iDESCENDING,0,0,2,0) For $i = 0 To UBound($arTmp)-1 $ARRAY[$i] = $arTmp[$i][1] Next Else ReDim $arTmp[UBound($ARRAY)][$UBound2nd+1] For $i = 0 To UBound($ARRAY)-1 For $k = 0 To $UBound2nd-1 $arTmp[$i][$k] = StringLen($ARRAY[$i][$k]) Next $arTmp[$i][$UBound2nd] = $i Next _ArraySort_2ary($arTmp, 0, $iDESCENDING) For $i = 0 To UBound($arTmp)-1 For $k = 0 To $UBound2nd-1 $arTmp[$i][$k] = $ARRAY[$arTmp[$i][$UBound2nd]][$k] Next Next ReDim $arTmp[UBound($ARRAY)][$UBound2nd] $ARRAY = $arTmp EndIf Return -1 EndFunc ;==>_ArraySortByLen