DelphiBasics
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
AnsiReplaceStrReplaces a part of one string with another
CopyCreate a copy of part of a string or an array
InsertInsert a string into another string
MoveCopy bytes of data from a source to a destination
StringReplaceReplace one or more substrings found within a string
 Download this web site as a Windows program.




 
Example code : A simple example
var
  source, target : AnsiString;
begin
  source := '123456789';
  target := StuffString(source, 2, 4, '-inserted-');

  ShowMessage('Source = '+source);
  ShowMessage('Target = '+target);
end;
Show full unit code
  Source = 123456789
  Target = 1-inserted-6789
 
Delphi Programming © Neil Moffatt 2002 - 2022. All rights reserved.  |  Home Page