Array.Concat

Syntax

Concat(Value: Variant; [Dimension: Integer = 1]): Variant;

Parameters

Value. The array that should be joined with the current array.

Dimension. The dimension, by which concatenation is executed.

Description

The Concat method concatenates elements of two arrays into a new array by extending the current array by the specified dimension.

Comments

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.

Example

Sub UserProc;
Var
    arrI1: Array[3Of Integer = [1234];
    arrI2: Array[3Of Integer = [975];
    arrI3: Array[22Of Integer = [[12], [34]];
    arrI4: Array[12Of Integer = [[56]];
    arrI5: Array[21Of Integer = [56];
    arrNewI: Array Of Integer;
    arrS1: Array[22Of String = [
        ["AA""AB"],
        ["BA""BB"]];
    arrS2: Array[22Of 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, 1As Array Of Integer;
    PrintArr2dV(arrNewI.ToVariantArray, "---Concatenate by the first dimension---");
    // by the second dimension
    arrNewI := arrI3.Concat(ArrI5, 2As Array Of Integer;
    PrintArr2dV(arrNewI.ToVariantArray, "---Concatenate by the second dimension---");
    // Character arrays
    arrNewS := arrS1.Concat(arrS2, 2As 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(1To arr.GetUpperBound(1Do
        Debug.Indent;
        Debug.Write("[");
        For j := arr.GetLowerBound(2To arr.GetUpperBound(2Do
            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:

Array