System.Delete

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure Delete(var S: String; Index: Integer; Count: Integer);

Properties

Type Visibility Source Unit Parent
procedure public System.pas System System

Description

Removes a substring from a string or elements range from a dynamic array.

S is a string-type or dynamic array-type variable. Index and Count are integer-type expressions.

Delete has a slightly different behavior depending on S type.

String-type

Delete removes a substring of Count characters from a string, starting at S[Index].

If Index is larger than the length of the string or less than 1, no characters are deleted.

If Count specifies more characters than the remaining in the string (counting from Index), Delete removes the rest of the string. If the value of Count is equal to or less than 0, then no characters are deleted.

Note: On strings, Delete uses one-based indexing even when zero-based strings are enabled.

Dynamic array-type

Delete removes an element range of Count elements from the array, counting from S[Index].

If Index is equal to or larger than the array's length or less than 0, no elements are deleted.

If Count specifies more elements than the remaining (counting from Index), Delete removes the rest of the array. No elements are deleted if Count is less than or equal to 0.

Dynamic Array Example

  
var
  A: array of integer;
begin
  ...
  A:=[1,2,3,4];
  Delete(A,1,2); //A will become [1,4]
  ...
end;

See Also

Code Examples