Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {==============================================================================]
- Explanation: Plants/places strs to index position in TSA.
- Like TSAInsert(), with an exception that this inserts array of strings.
- Returns the highest index from TSA in the end.
- [==============================================================================}
- function TSAPlant(var TSA: TStrArray; index: Integer; strs: TStrArray): Integer;
- var
- i, l, h: Integer;
- begin
- h := High(strs);
- if (h > -1) then
- begin
- l := Length(TSA);
- SetLength(TSA, (l + (h + 1)));
- if (index < 0) then
- index := 0;
- if (index > l) then
- index := l;
- for i := (l + (h + 1) - 1) downto (index + (h + 1)) do
- Swap(TSA[i], TSA[(i - (h + 1))]);
- for i := 0 to h do
- TSA[(i + index)] := string(strs[i]);
- end;
- Result := High(TSA);
- end;
- var
- tmp: TStrArray;
- h, i: Integer;
- begin
- ClearDebug;
- tmp := ['a', 'b', 'f', 'g'];
- TSAPlant(tmp, 2, ['c', 'd', 'e']);
- h := High(tmp);
- for i := 0 to h do
- WriteLn(tmp[i]);
- end.
Advertisement
Add Comment
Please, Sign In to add comment