Name

Delete Procedure

Syntax

procedure Delete(var Str: string; StartingIndex, Count: Integer);

Description

The Delete procedure removes Count characters from a string, starting at StartingIndex. If Count is more than the number of characters remaining in the string, Delete deletes the rest of the string, starting from StartingIndex. Delete is not a real procedure.

Tips and Tricks

  • The first character of a string has index 1.

  • If StartingIndex is not positive or is greater than the length of the string, Delete does not change the string.

  • If the Count is greater than the characters remaining after the starting index, the rest of the string is deleted.

  • If you want to delete characters at the end of a string, SetLength is slightly faster than calling the more general purpose Delete.

Example

// Remove a drive letter from the front of a path.
procedure RemoveDriveLetter(var Path: string);
begin
  // First make sure the path has a drive letter in front.
  if (Length(Path) >= 2) and (Path[2] = ':') then
    // Delete the first two characters of the path.
    Delete(Path, 1, 2);
end;

See Also

Copy Function, Insert Procedure, SetLength Procedure, SetString Procedure
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset