Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {==============================================================================]
- Explanation: Returns str stuffed with s.
- pos1=start position, pos2=finish position.
- With pos1 > pos2 s will be reversed.
- [==============================================================================}
- function StuffEx(str, s: string; pos1, pos2: Integer): string;
- var
- i, l: Integer;
- begin
- Result := str;
- l := Length(Result);
- if (pos1 < 1) then
- pos1 := 1;
- if (pos1 > l) then
- pos1 := l;
- if (pos2 < 1) then
- pos2 := 1;
- if (pos2 > l) then
- pos2 := l;
- case (pos1 > pos2) of
- True:
- begin
- Delete(Result, pos2, ((pos1 - pos2) + 1));
- l := Length(s);
- SetLength(str, l);
- for i := l downto 1 do
- str[i] := Char(s[((l - i) + 1)]);
- Insert(str, Result, pos2);
- end;
- False:
- begin
- Delete(Result, pos1, ((pos2 - pos1) + 1));
- Insert(s, Result, pos1);
- end;
- end;
- end;
- var
- str: string;
- begin
- ClearDebug;
- str := 'StuffEx test to see this is working..!';
- WriteLn(StuffEx(str, '() WORKS', 8, 37));
- WriteLn(StuffEx(str, 'SKROW )(', 37, 8));
- end.
Advertisement
Add Comment
Please, Sign In to add comment