Name
Insert Procedure
Syntax
procedure Insert(const Ins: string; var Str: string; Index: Integer);
Description
The
Insert
procedure inserts the string
Ins
into the string Str
at the
position Index
. If Index
is
≤ 1, Ins
is inserted at the beginning of
Str
. If Index
is past the end
of the string, Ins
is appended to the end of
Str
.
Insert
is not a real procedure.
Tips and Tricks
The first character of a string has index 1.
Example
// Insert a drive letter at the front of a path.
procedure InsertDriveLetter(var Path: string; const Drive: Char);
begin
// First make sure the path does not have a drive letter in front.
if (Length(Path) < 2) or (Path[2] <> ':') then
// Insert the drive at the start of the path.
Insert(Drive + ':', Path, 1);
end;
See Also
Copy Function, Delete Procedure, SetLength Procedure, SetString Procedure |
Get Delphi in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.