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 |
Concat |
|
Concatenates one or more strings into one string |
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 |
StringOfChar |
|
Creates a string with one character repeated many times |
StringReplace |
|
Replace one or more substrings found within a string |
WrapText |
|
Add line feeds into a string to simulate word wrap |
Trim |
|
Removes leading and trailing blanks from a string |
TrimLeft |
|
Removes leading blanks from a string |
TrimRight |
|
Removes trailing blanks from a string |
|
|
|
|
Example code : Deleting characters from 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; interface uses // The System unit does not need to be defined 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 : string;
begin
Source := '12345678'; Delete(Source, 3, 4); // Delete the 3rd, 4th, 5th and 6th characters
ShowMessage('Source now : '+Source);
end; end.
|
Hide full unit code |
Source now : 1278
|
|