Insert
Insert one string or dynamic array in another.
Declaration
Source position: system.fpd line 52
procedure Insert(const source: string; var S: string;
const Index: Integer);
procedure Insert(const source: DynaArrayType; var S: DynArrayType;
const Index: Integer);
Description
Insert inserts string 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 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
Name | Description |
---|---|
Copy | Copy part of a string. |
Delete | Delete elements (characters) from a string or dynamic array. |
Pos | Search for substring in a string. |
Example
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.