Array copy_from Method
Syntax
Arguments
- arrayPointer
An array of elements.
- flagsCharacter
Optional flags. Multiple flags can be combined, e.g. "TZ". Available flags include:
- "A"
Appends entries from the Source array to the Target array. If the Target array has empty entries at the end of the array, the Source items are added after the empty entries.
- "T"
Truncate the array. Resize the target array so that it matches the size of the source array.
- "Z"
Empty the contents of the target array before copying (i.e. equivalent to <array>.clear()).
Description
Copies elements from one array and inserts them into another.
Discussion
The <array>.copy_from() method copies elements from a source array into a target array, overwriting existing elements and resizing the array as necessary.
Example
delete target
dim target[2] as C
target.initialize(comma_to_crlf("a,b"))
dim source[3] as C
source.initialize(comma_to_crlf("1,2,3"))
target.copy_from(source)
? target.dump()
= 1
2
3The target array is now the same as the source array.
delete target
dim target[2] as c
target.initialize(comma_to_crlf("a,b"))
target.copy_from(source,"A")
? target.dump()
= a
b
1
2
3The target array now has 5 slots - its original 2 slots and the 3 that were appended from the source array.
delete target
dim target[5] as c
target.initialize(comma_to_crlf("a,b,c,d,e"))
target.copy_from(source)
? target.dump()
= 1
2
3
d
eThe first 3 entries in the target array are copied from the source array, but the target array still has 5 slots and slots 4 and 5 have not changed.
delete target
dim target[5] as c
target.initialize(comma_to_crlf("a,b,c,d,e"))
target.copy_from(source,"t")
?target.dump()
= 1
2
3Because the T option was used, the target array now only has 3 slots - the extra 2 slots at the end were truncated.
dim tp[3] as p
tp.initialize_properties("prop1|prop2",comma_to_crlf("a|AA,b|BB,c|CC"))
dim sp[1] as p
sp[1].NewProp1 = "1"
tp.copy_from(sp,"T")
? p[1]
= NewProp1 = "1"
prop1 = "a"
prop2 = "AA"
? p.size()
= 1The target array now has 3 properties for slot 1 (NewProp1, prop1 and prop2). It has combined the properties from the source and target arrays.
The target array also only has 1 slot because the T flag was used and the source array only had one slot.
delete tp
dim tp[3] as p
tp.initialize_properties("prop1|prop2",comma_to_crlf("a|AA,b|BB,c|CC"))
tp.copy_from(sp,"TZ")
? p[1]
= NewProp1 = "1"The target array only has 1 property for slot 1 (because the Z flag was used, and the source array only has one property for slot 1).