Sign in Join
FPDoc Onlineexperiment

Insert procedure

In unit System

Insert one string or dynamic array in another.

Declaration

pascal
procedure Insert(const source: string; var S: string; 
 const Index: Integer)

Description

Insert inserts string or character Source in string S, at position Index, shifting all characters after Index to the right. The resulting string is truncated at 255 characters, if needed. (i.e. for shortstrings)

Index is a 1-based index. if Index is less than 1, the insert of Source happens at the start of the string, as if the value 1 was specified.

If the value of Index is larger than the length of the string S, Source is appended to the string S.

For dynamic arrays, Insert inserts an element Source or the elements of array Source in array S, at position Index, shifting all elements after Index to the right.

Index is a 0-based index. if Index is less than 0, the insert of Source happens at position0.

If the value of Index is larger than the length of the array S, Source is appended to the array S.

Errors

None.

See also

Example: ex33

pascal
Program Example33;

{ Program to demonstrate the Insert function. }

Var S : String;

begin
  S:='Free Pascal is difficult to use !';
  Insert ('NOT ',S,pos('difficult',S));
  writeln (s);
end.

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.