#1 2024-05-01 22:42

bdpq
Member
Registered: 2015-11-05
Posts: 9

New function to Concatenate Arrays?

I have been using a rather complicated function to concatenate 2 arrays into one. Is it possible to have a built-in function that does this in future releases?

It would be nice to allow '+' to work on TWideStringArray directly so that
Array1 + array2 + ... can be allowed?

Thanks for consideration!

Offline

#2 2024-05-02 14:13

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,393

Re: New function to Concatenate Arrays?

The current Pascal Script implementation is not capable of overloading the '+' operator to make it work with TWideStringArray or any other custom types.

However, we can add built-in functions to offer this functionality. Keep an eye on the next development version.

Offline

#3 2024-05-07 10:20

bdpq
Member
Registered: 2015-11-05
Posts: 9

Re: New function to Concatenate Arrays?

this is what I am using now in my ever-growing includes. tongue  Just copying the values as it loops through.  Really looking forward to a built-in function!

function concatArrays(const r1, r2:TWideStringArray):TWideStringArray;
var i: Integer;
begin
	SetLength(result, length(r1) + Length(r2));
	for i := 0 to length(r1)-1 do result[i] := r1[i];
	for i := 0 to length(r2)-1 do result[i + length(r1)] := r2[i];	
end;

Offline

#4 2024-05-21 14:17

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,393

Re: New function to Concatenate Arrays?

In v7.5.0.3 Beta several string array management functions were added to Pascal Script.

function WideConcatStringArrays(const A, B: TWideStringArray): TWideStringArray;
function WideCopyStringArray(const Strings: TWideStringArray; Index, Count: Integer): TWideStringArray;
procedure WideAppendStringArray(var Strings: TWideStringArray; const NewString: WideString);

Offline

Board footer

Powered by FluxBB