Concat(Value: Variant; [Dimension: Integer = 1]): Variant;
Value. The array that should be joined with the current array.
Dimension. The dimension, by which concatenation is executed.
The Concat method concatenates elements of two arrays into a new array by extending the current array by the specified dimension.
Concatenated arrays should be equal in size by all dimensions, except for the Dimension dimension by which concatenation is executed. The Dimension dimension is used to increase size of the output array by the number of elements of concatenated arrays.
NOTE. When the method works with big amounts of data, more memory is used because memory should be allocated for the created concatenated array.
Sub UserProc;
Var
arrI1: Array[3] Of Integer = [1, 2, 3, 4];
arrI2: Array[3] Of Integer = [9, 7, 5];
arrI3: Array[2, 2] Of Integer = [[1, 2], [3, 4]];
arrI4: Array[1, 2] Of Integer = [[5, 6]];
arrI5: Array[2, 1] Of Integer = [5, 6];
arrNewI: Array Of Integer;
arrS1: Array[2, 2] Of String = [
["AA", "AB"],
["BA", "BB"]];
arrS2: Array[2, 2] Of String = [
["CC", "CD"],
["DC", "DD"]];
arrNewS: Array Of String;
Begin
// Concatenate two single-dimensional arrays
arrNewI := arrI1.Concat(ArrI2) As Array Of Integer;
Debug.WriteLine("Length: " + arrNewI.Length.ToString);
// Concatenate two two-dimensional arrays
// by the first dimension
arrNewI := arrI3.Concat(ArrI4, 1) As Array Of Integer;
PrintArr2dV(arrNewI.ToVariantArray, "---Concatenate by the first dimension---");
// by the second dimension
arrNewI := arrI3.Concat(ArrI5, 2) As Array Of Integer;
PrintArr2dV(arrNewI.ToVariantArray, "---Concatenate by the second dimension---");
// Character arrays
arrNewS := arrS1.Concat(arrS2, 2) As Array Of String;
PrintArr2dV(arrNewS.ToVariantArray, "---Character arrays---");
End Sub UserProc;
Sub PrintArr2dV(arr: Array Of Variant; title: String);
Var
i, j: Integer;
Begin
Debug.WriteLine(title);
Debug.WriteLine("[");
For i := arr.GetLowerBound(1) To arr.GetUpperBound(1) Do
Debug.Indent;
Debug.Write("[");
For j := arr.GetLowerBound(2) To arr.GetUpperBound(2) Do
Debug.Write(String.Format("{0}{1}", arr[i, j], (j < arr.GetUpperBound(2)? ", " : "")));
End For;
Debug.WriteLine(String.Format("{0}", (i < arr.GetUpperBound(1)? "], " : "]")));
Debug.Unindent;
End For;
Debug.WriteLine("]");
Debug.WriteLine("");
End Sub PrintArr2dV;
Different array types are concatenated during example execution. The output arrays will be displayed in the development environment console:
Unit execution started
Length: 6
---Concatenate by the first dimension---
[
[1, 2],
[3, 4],
[5, 6]
]
---Concatenate by the second dimension---
[
[1, 2, 5],
[3, 4, 6]
]
---Character arrays---
[
[AA, AB, CC, CD],
[BA, BB, DC, DD]
]
Unit execution finished
See also: