Function Reference


_ArrayDelete

Deletes the specified element(s) from the specified 1D or 2D array

#include <Array.au3>
_ArrayDelete ( ByRef $aArray, $vRange )

Parameters

$aArray Array to modify
$vRange Element(s) to delete - either a single index, a range string or a 1D array with a count in the [0] element (see example for details)

Return Value

Success: the new size of the array (see remarks)
Failure: -1 and sets the @error flag to non-zero.
@error: 1 - $aArray is not an array
2 - $aArray is not a 1D or 2D array
3 - $vRange is not a valid range string
4 - $vRange is not a 1D array or has only 1 element
5 - $vRange content is outside array bounds

Remarks

$vRange can be a string containing the rows which are to be deleted. It can be a single number or a range denoted by the first and last lines separated by a hyphen (-) - multiple items are separated by a semi-colon (;).

$vRange can also be a 1D array listing all rows to be deleted with the count in the [0] element].

In either case, the rows need not be in ascending order and can be duplicated.

The function does NOT update any count element within the array, but the return value of the function (if successful) gives the new highest row index of the array.

Related

_ArrayAdd, _ArrayInsert

Example

#include <Array.au3>

Local $aArray[5] = [0, 1, 2, 3, 4]

_ArrayDisplay($aArray, "Original")
_ArrayDelete($aArray, 2)
_ArrayDisplay($aArray, "Element 2 deleted")

Local $aArray_Base[25][4]
For $i = 0 To 24
        For $j = 0 To 3
                $aArray_Base[$i][$j] = $i & "-" & $j
        Next
Next

; Single row
$aArray = $aArray_Base
_ArrayDisplay($aArray, "BEFORE deletion")
_ArrayDelete($aArray, 7)
_ArrayDisplay($aArray, "SINGLE ROW deleted")

; Range string
$aArray = $aArray_Base
Local $sRange = "0;11-15;24"
_ArrayDisplay($aArray, "BEFORE deletion")
_ArrayDelete($aArray, $sRange)
ConsoleWrite(" " & @error & @CRLF)
_ArrayDisplay($aArray, "RANGE STRING deleted")

; 1D array
$aArray = $aArray_Base
Local $aDel[4] = [3, 5, 11, 13]
_ArrayDisplay($aArray, "BEFORE deletion")
_ArrayDelete($aArray, $aDel)
_ArrayDisplay($aArray, "RANGE ARRAY deleted")