[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] Reference for unit 'System' (#rtl)

Copy

Copy part of a string.

Declaration

Source position: line 0

function Copy(

  S: AStringType;

  Index: Integer;

  Count: Integer

):String;

function Copy(

  A: DynArrayType;

  Index: Integer;

  Count: Integer

):DynArray;

Description

Copy returns a string which is a copy if the Count characters in S, starting at position Index. If Count is larger than the length of the string S, the result is truncated. If Index is larger than the length of the string S, then an empty string is returned. Index is 1-based.

For dynamical arrays, Copy returns a new dynamical array of the same type as the original one, and copies Count elements from the old array, starting at position Index.

Errors

None.

See also

Delete

  

Delete part of a string.

Insert

  

Insert one string in another.

Pos

  

Search for substring in a string.

Example

Program Example11;

{ Program to demonstrate the Copy function. }

Var S,T : String;

begin
  T:='1234567';
  S:=Copy (T,1,2);   { S:='12'   }
  S:=Copy (T,4,2);   { S:='45'   }
  S:=Copy (T,4,8);   { S:='4567' }
end.
The latest version of this document can be found at lazarus-ccr.sourceforge.net.