Insert a string into another string System unit
 procedure Insert ( const InsertStr : string; var TargetStr : string; Position : Integer ) ;
The Insert procedure inserts one string, InsertStr into another string, TargetStr at the given Position.
The TargetStr string characters from the Position character are moved right to make way for the InsertStr string.
The length of TargetStr is now the sum of the length of the two strings.
To insert into the start of TargetStr, set Position to 1 or less.
To append to the end of TargetStr, set Position after the last character of TargetStr.
The first character of a string is at position 1

Arrays start at index 0.
Related commands
AnsiReplaceStr Replaces a part of one string with another
Concat Concatenates one or more strings into one string
Copy Create a copy of part of a string or an array
Delete Delete a section of characters from a string
Move Copy bytes of data from a source to a destination
StringOfChar Creates a string with one character repeated many times
StringReplace Replace one or more substrings found within a string
StuffString Replaces a part of one string with another
WrapText Add line feeds into a string to simulate word wrap
 Author links

 Buy Website Traffic at

 Buy Proxies at
 Download this web site as a Windows program.

Example code : Inserting into the middle of a string
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
unit Unit1;
  // The System unit does not need to be defined
  Forms, Dialogs;
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
Form1: TForm1;
{$R *.dfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);

  Target : string;
  Target := '12345678';
  Insert('-+-', Target, 3);
  ShowMessage('Target : '+Target);
Hide full unit code
   Target : 12-+-345678
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page