Name

Copy Function

Syntax

function Copy(Source: string; StartingIndex, Count: Integer): string;
function Copy(Source: array; StartingIndex, Count: Integer): array;

Description

The Copy function creates a copy of part of a string or dynamic array. The result is a new string or dynamic array. The new string or array starts with the element at StartingIndex in Source. The new string or array contains up to Count elements. If Count exceeds the number of items remaining in the source string or array, the elements from StartingIndex to the end of the string or array are copied.

Copy is not a real function.

Tips and Tricks

  • If StartingIndex is less than zero or past the end of Source, the result is an empty string or array.

  • The length of the new string or array is Count unless the Source has fewer than Count elements to copy, in which case Copy copies all the elements up to the end of the string or array.

  • The first index of a string is 1. The first index of a dynamic array is 0.

  • A convenient way to copy all the elements of Source from the starting index is to use MaxInt as the Count.

See Also

Delete Function, High Function, Insert Procedure, Length Function, Low Function, SetLength Procedure, SetString Procedure, Slice Function

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.