Easiest way to replace item in array...

Is there a fast and efficient way to replace an item in a one dimensional array? or do I need to loop through the items and just replace the item that way?

NG,

LVL 13
nike_golfAsked:
Who is Participating?
 
Jim HornConnect With a Mentor Microsoft SQL Server Developer, Architect, and AuthorCommented:
Uhh, you can just write over it.

YourArray(SomeNumber) = SomeValue
0
 
nike_golfAuthor Commented:
duh... thx.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If you are looking for a fast way to determine the INDEX of an item in an array...then No.  You have to loop over it to find the right spot that you want to overwrite.

If you need a fast way to do LOOKUPS then use a Collection instead of an Array.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
dentabCommented:
Sorry, was jim horns answer what you were looking for?

If the array is sorted, then a binary tree search is a good way of quickly finding an item

To remove an item is harder

To swap an Item with another part of the array requires a temporary variable of the same type
  e.g.

tmpString = aitem(2)
aitem(2) = aitem(4)
aitem(4) = tmpString

Or are none of these the type of thing you are asking about?
0
 
dentabCommented:
Or if you want to replace all items of a certain value...

That either requires a loop (easy & fast on small arrays)
or a binary search on a sorted array, followed by a loop (harder but very fast for large arrays)
0
 
nike_golfAuthor Commented:
Senial moment on my behalf... thanks guy's..
0
All Courses

From novice to tech pro — start learning today.