xHarbour Reference Documentation > Function Reference |
Inserts an element into an array.
AIns( <aArray>, <nElement>, [<xValue>], [<lGrow>] ) --> aArray
The function returns a reference to <aArray>.
The array function AIns() inserts a new element at position <nElement> into the array <aArray>. All subsequent elements are shifted down by one position so that the last element is lost when the function returns. This default behaviour leaves the number of elements in the array unchanged.
The new array element is initialized with NIL, but can be assigned a value when parameter <xValue> is not NIL.
If the fourth parameter <lGrow> is specified as .T. (true), the function first adds a new element and then shifts all elements down, beginning at the specified position. This way, the last element is preserved and the number of elements is enlarged by one.
See also: | AAdd(), ACopy(), ADel(), AEval(), AFill(), ASize() |
Category: | Array functions |
Source: | vm\arrayshb.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// This example demonstrates two results of inserting an // array element PROCEDURE Main() LOCAL aArray := { "A", "B", "C" } AIns( aArray, 2 ) ? Len( aArray ) // result: 3 ? aArray[1], aArray[2], aArray[3] // result: A NIL B AIns( aArray, 2, "C", .T. ) ? Len( aArray ) // result: 4 ? aArray[1], aArray[2], aArray[3], aArray[4] // result: A C NIL B RETURN
http://www.xHarbour.com