RAD Studio VCL Reference
System.Insert Function

Inserts a substring into a string beginning at a specified point.

procedure Insert(Source: string; var S: string; Index: Integer);
Insert(AnsiString Source, AnsiString S, int Index);

In Delphi code, Insert merges Source into S at the position S[index]. 

Source is a string-type expression. S is a string-type variable of any length. Index is an integer-type expression. It is a character index and not a byte index. 

If Index is less than 1, it is mapped to a 1. If it is past the end of the string, it is set to the length of the string, turning the operation into an append. 

If the Source parameter is an empty string, Insert does nothing. 

Insert throws an EOutOfMemory exception if it is unable to allocate enough memory to accomodate the new returned string.  

Delphi Examples: 


This example uses the Insert function to edit a string.
procedure TForm1.Button1Click(Sender: TObject);
  S: string;
  S := 'Honest Lincoln';
  Canvas.TextOut(10, 10, S);
  Insert('Abe ', S, 8);                    { 'Honest Abe Lincoln' }
  Canvas.TextOut(10, 40, S);


Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!