Array concatenation: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: Changed to Wren S/H) |
(added a more complete compilable example) |
||
Line 1,923: | Line 1,923: | ||
Since FPC (Free Pascal compiler) version 3.2.0., the dynamic array concatenation operator <code>+</code> is available, provided <code>{$modeSwitch arrayOperators+}</code> (which is enabled by default in <code>{$mode Delphi}</code>). |
Since FPC (Free Pascal compiler) version 3.2.0., the dynamic array concatenation operator <code>+</code> is available, provided <code>{$modeSwitch arrayOperators+}</code> (which is enabled by default in <code>{$mode Delphi}</code>). |
||
<syntaxhighlight lang="pascal"> array2 := array0 + array1</syntaxhighlight> |
<syntaxhighlight lang="pascal"> array2 := array0 + array1</syntaxhighlight> |
||
Alternatively, one could use <code>concat()</code> which is independent of above modeswitch and mode: |
Alternatively, one could use <code>concat()</code> which is independent of above modeswitch and mode. Neither option requires the use of any libraries.: |
||
<syntaxhighlight lang="pascal"> array2 := concat(array0, array1);</syntaxhighlight> |
<syntaxhighlight lang="pascal"> array2 := concat(array0, array1);</syntaxhighlight> |
||
Both options do not require any libraries. |
|||
A more complete example: |
|||
<syntaxhighlight lang="pascal"> |
|||
Program arrayConcat; |
|||
{$mode delphi} |
|||
type |
|||
TDynArr = array of integer; |
|||
var |
|||
i: integer; |
|||
arr1, arr2, arrSum : TDynArr; |
|||
begin |
|||
arr1 := [1, 2, 3]; |
|||
arr2 := [4, 5, 6]; |
|||
arrSum := arr1 + arr2; |
|||
for i in arrSum do |
|||
write(i, ' '); |
|||
writeln; |
|||
end. |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
1 2 3 4 5 6 |
|||
</pre> |
|||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |