Unit 'System' Package
[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] [#rtl]

Copy

Copy part of a string or dynamic array.

Declaration

Source position: system.fpd line 82

function Copy(

  S: AStringType;

  Index: SizeInt;

  Count: SizeInt

):string;

function Copy(

  A: DynArrayType;

  Index: SizeInt;

  Count: SizeInt

):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 dynamic arrays, Copy returns a new dynamic array of the same type as the original one, and copies Count elements from the old array, starting at the position in Index. Both the Index and Count arguments are optional: if none are specified, the whole array is copied. This is useful to make sure you have a reference count of 1 on the dynamic array (i.e. similar to UniqueString). Note that the copy is a shallow copy, i.e. sub-arrays are not copied as well.

The Count argument can be omitted. In that case, the string (or dynamic array) is copied from the position Index till the end of the string or array.

Errors

None.

See also

Delete

  

Delete elements (characters) from a string or dynamic array.

Insert

  

Insert one string or dynamic array 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.

Documentation generated on: Oct 27 2024