# Two Dimensional _ArrayDelete

## Recommended Posts

Ok, I obviously don't know if this UDF already exists (which is why I wrote it).

I've got a bunch of two dimensional arrays that I have to manipulate the heck out of. One of the things that needs to be done is the removal of a row of data based on a string value, so I wrote this:

CODE
Func _2DArrayDelete(\$array, \$iIndex, \$iSort, \$search)

#cs ===================================================

Function: This function will delete a 'row' of data

from a 2-D array and return the adjusted array.

Required: #include <Array.au3>

\$array = 2-Dimensional array to be processed

\$iIndex = The starting 'column' of the array that

will be moved up. (ie, if there is data

in [n][0] and [n][1] that doesn't need

to be moved along with [n][2] - [n][x]

then this value would be set to 2).

\$iSort = The 'column' to sort; array is sorted in

asending order based on the 'column' at

this value.

\$search = The string that will be searched for in

the \$iSort 'column'.

#ce ===================================================

_ArraySort(\$array, 0, 1, -1, UBound(\$array, 2), \$iSort)

\$start = 0

\$end = 0

For \$x = 1 To \$array[0][0]

If \$start = 0 And \$array[\$x][\$iSort] = \$search Then \$start = \$x

If \$start > 0 And \$array[\$x][\$iSort] = \$search Then \$end = \$x

If \$array[\$x][\$iSort] > \$search Then ExitLoop

Next

\$move = \$end - \$start + 1

For \$x = \$start To \$array[0][0]-\$move

For \$y = \$iIndex To UBound(\$array, 2)-1

\$array[\$x][\$y] = \$array[\$x+\$move][\$y]

Next

Next

\$array[0][0] -= \$move

ReDim \$array[\$array[0][0]+1][uBound(\$array, 2)]

Return \$array

EndFunc

I know my documentation isn't the clearest in the world, but that's the best I could do. I know how it works in my head, but I couldn't translate well to e-paper. Lemme know what you think.

##### Share on other sites

Hi,

Thanks; a detailed set of parameters!

I have an "_ArrayDelete2D" in my array2D.au3 UDF, not so detailed , linked from my signature;

could I include yours as an option in that UDF?

best, Randall

##### Share on other sites

Hi,

Thanks; a detailed set of parameters!

I have an "_ArrayDelete2D" in my array2D.au3 UDF, not so detailed , linked from my signature;

could I include yours as an option in that UDF?

best, Randall

Most definately! Maybe change the name to _ArrayDelete2DRowSearch or something since it will only delete a row that contains the search string.

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...