• Offizieller Beitrag

    Ich kanns nicht ändern, irgendwie liebe ich Arrays :]

    Hier eine Löschfunktion für leere Zeilen / Spalten

    _Array2DEmptyDel(ByRef $avArray [, $Col=0])

    - arbeitet mit 1D / 2D Arrays
    - es werden leere Einträge entfernt
    - in 2D Arrays können optional statt Zeilen leere Spalten entfernt werden
    - Standardeinstellung ist Zeilen entfernen

    Spoiler anzeigen
    [autoit]

    #include <array.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Dim $ar1[5]
    Dim $ar2[5][4]

    [/autoit] [autoit][/autoit] [autoit]

    $ar1[0]=0
    $ar1[1]=1
    $ar1[3]=0
    $ar1[4]=4

    [/autoit] [autoit][/autoit] [autoit]

    $ar2[0][0]="A"
    $ar2[1][0]="A"

    [/autoit] [autoit][/autoit] [autoit]

    $ar2[3][0]="A"
    $ar2[4][0]="A"
    $ar2[0][1]="B"
    $ar2[1][1]="B"

    [/autoit] [autoit][/autoit] [autoit]

    $ar2[3][1]="B"
    $ar2[4][1]="B"
    $ar2[0][3]="D"
    $ar2[1][3]="D"

    [/autoit] [autoit][/autoit] [autoit]

    $ar2[3][3]="D"
    $ar2[4][3]="D"

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _ArrayDisplay($ar1, "1D")
    _Array2DEmptyDel($ar1)
    _ArrayDisplay($ar1, "1D - leere gelöscht")

    [/autoit] [autoit][/autoit] [autoit]

    _ArrayDisplay($ar2, "2D")
    _Array2DEmptyDel($ar2)
    _ArrayDisplay($ar2, "2D - leere Zeilen gelöscht")
    _Array2DEmptyDel($ar2,1)
    _ArrayDisplay($ar2, "2D - und noch leere Spalten gelöscht")

    [/autoit] [autoit][/autoit] [autoit]

    ;----------------------------------------------------------------------------------------------------------------------
    ; Function _Array2DEmptyDel(ByRef $avArray [, $Col=0])
    ;
    ; Description Delete empty Array elements
    ; Delete all emty Rows or all empty Columns
    ; Works also with 1D-Array (only Rows)
    ;
    ; Parameter $avArray Given Array
    ; optional $Col set 1 to delete empty Columns; default is 0 to delete empty Rows
    ;
    ; Return Succes -1 ByRef the given Array without empty Elements, resized
    ; Failure 0 and set @error = 1
    ;
    ; Author BugFix ([email='bugfix@autoit.de'][/email])
    ;----------------------------------------------------------------------------------------------------------------------
    Func _Array2DEmptyDel(ByRef $avArray, $Col=0)
    If ( Not IsArray($avArray) ) Then
    SetError(1)
    Return 0
    EndIf
    Local $UBound2nd = UBound($avArray,2)
    If @error = 2 Then
    Local $arTMP[1]
    For $i = 0 To UBound($avArray)-1
    If StringLen($avArray[$i] > 0) Then
    If StringLen($arTMP[UBound($arTMP)-1]) = 0 Then
    $arTMP[UBound($arTMP)-1] = $avArray[$i]
    Else
    ReDim $arTMP[UBound($arTMP)+1]
    $arTMP[UBound($arTMP)-1] = $avArray[$i]
    EndIf
    EndIf
    Next
    Else
    If $Col = 0 Then
    Local $arTMP[1][$UBound2nd], $val, $len
    For $i = 0 To UBound($avArray)-1
    $val = ''
    For $k = 0 To $UBound2nd-1
    $val &= $avArray[$i][$k]
    Next
    If StringLen($val) > 0 Then
    $len = 0
    For $k = 0 To UBound($arTMP,2)-1
    $len &= StringLen($arTMP[UBound($arTMP)-1][$k])
    Next
    If $len = 0 Then
    For $k = 0 To $UBound2nd-1
    $arTMP[UBound($arTMP)-1][$k] = $avArray[$i][$k]
    Next
    Else
    ReDim $arTMP[UBound($arTMP)+1][$UBound2nd]
    For $k = 0 To $UBound2nd-1
    $arTMP[UBound($arTMP)-1][$k] = $avArray[$i][$k]
    Next
    EndIf
    EndIf
    Next
    Else
    Local $arTMP[UBound($avArray)][1], $val, $len
    For $k = 0 To $UBound2nd-1
    $val = ''
    $notEmpty = 0
    For $i = 0 To UBound($avArray)-1
    $val &= $avArray[$i][$k]
    If StringLen($val) > 0 Then
    $notEmpty = 1
    ExitLoop
    EndIf
    Next
    If $notEmpty = 1 Then
    $len = 0
    For $i = 0 To UBound($arTMP)-1
    $len &= StringLen($arTMP[$i][UBound($arTMP,2)-1])
    Next
    If $len = 0 Then
    For $i = 0 To UBound($avArray)-1
    $arTMP[$i][0] = $avArray[$i][$k]
    Next
    Else
    ReDim $arTMP[UBound($avArray)][UBound($arTMP,2)+1]
    For $i = 0 To UBound($avArray)-1
    $arTMP[$i][UBound($arTMP,2)-1] = $avArray[$i][$k]
    Next
    EndIf
    EndIf
    Next
    EndIf
    EndIf
    $avArray = $arTMP
    Return -1
    EndFunc ;==>_Array2DEmptyDel

    [/autoit]