DelphiBasics
Delete
Procedure
Delete a section of characters from a string System unit
 procedure Delete(var Source string; StartChar Integer; Count Integer);
Description
The Delete procedure deletes up to Count characters from the passed parameter Source string starting from position StartChar.
 
No error is produced if Count exceeds the remaining character count of Source.
 
The first character of a string is at position 1.
Notes
If the StartChar is before the first, or after the last character of Source, then no characters are deleted.

Delete(myString, 5, MaxInt);

  is equivalent to the better performing :

SetLength(myString, 4);
Related commands
ConcatConcatenates one or more strings into one string
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
StringOfCharCreates a string with one character repeated many times
StringReplaceReplace one or more substrings found within a string
WrapTextAdd line feeds into a string to simulate word wrap
TrimRemoves leading and trailing blanks from a string
TrimLeftRemoves leading blanks from a string
TrimRightRemoves trailing blanks from a string
 Download this web site as a Windows program.




 
Example code : Deleting characters from the middle of a string
var
  Source : string;

begin
  Source := '12345678';
  Delete(Source, 3, 4);    // Delete the 3rd, 4th, 5th and 6th characters
  ShowMessage('Source now : '+Source);
end;
Show full unit code
  Source now : 1278
 
Delphi Programming © Neil Moffatt 2002 - 2022. All rights reserved.  |  Home Page