Jump to content
Sign in to follow this  

Two Dimensional _ArrayDelete

Recommended Posts


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

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:

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


$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]



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

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

Return $array


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 this post

Link to post
Share on other sites


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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this