Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {==============================================================================]
- Explanation: Returns TSA stuffed with strs.
- iFrom=start position, iCount=count of chars to stuff with.
- [==============================================================================}
- function TSAStuff(TSA, strs: TStrArray; iFrom, iCount: Integer): TStrArray;
- var
- h, i, l: Integer;
- begin
- l := Length(TSA);
- SetLength(Result, l);
- for i := 0 to (l - 1) do
- Result[i] := string(TSA[i]);
- if (iFrom < 0) then
- iFrom := 0;
- if (iFrom > (l - 1)) then
- iFrom := (l - 1);
- if ((iCount > 0) and (iFrom <= (l - 1))) then
- Delete(Result, iFrom, iCount);
- h := High(strs);
- if (h > -1) then
- begin
- l := Length(Result);
- SetLength(Result, (l + (h + 1)));
- if (iFrom > l) then
- iFrom := l;
- for i := (l + h) downto (iFrom + (h + 1)) do
- Swap(Result[i], Result[(i - (h + 1))]);
- for i := 0 to h do
- Result[(i + iFrom)] := string(strs[i]);
- end;
- end;
- var
- a, b: TStrArray;
- h, i: Integer;
- begin
- ClearDebug;
- a := ['a', 'b', 'b', 'x', 'y', 'z', 'f', 'f', 'g'];
- b := TSAStuff(a, ['c', 'd', 'e'], 2, 5);
- h := High(b);
- for i := 0 to h do
- WriteLn(b[i]);
- end.
Advertisement
Add Comment
Please, Sign In to add comment