SmartPascal
StuffString
Function
Replaces a part of one string with another StrUtils unit
 function StuffString ( const Source : string; Start, Length : Cardinal; const SubString : string ) : string;
Description
The StuffString function inserts a SubString into another string, replacing Length characters at position Start.
 
If the length is -1, then teh string is simply inserted, and does not replace any characters.
Notes
Strings are indexed from 1 (arrays from 0).
Related commands
AnsiReplaceStr Replaces a part of one string with another
Copy Create a copy of part of a string or an array
Insert Insert a string into another string
Move Copy bytes of data from a source to a destination
StringReplace Replace one or more substrings found within a string
 
Example code : A simple example
// 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;
 
interface
 
uses
  StrUtils,   // Unit containing the StuffString command
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

var
  source, target : AnsiString;
begin
  source := '123456789';
  target := StuffString(source, 2, 4, '-inserted-');

  ShowMessage('Source = '+source);
  ShowMessage('Target = '+target);
end;
 
end.
Hide full unit code
   Source = 123456789
   Target = 1-inserted-6789