Documentation
Back to website >

Copy (Pascalscript)

Description

The Copy function returns a substring of a string.

Syntax

function Copy(S: String; Index, Count: Integer): String;

Arguments

S is an expression of type String and contains the text from which the subtext is to be copied.

Index is an integer value and specifies the position within S from which the copy operation is to begin. If the index is greater than the length of S, Copy returns an empty string.

Count is an integer value and specifies how many characters are to be copied. If Count specifies more characters than are available, only the characters up to the end of S are returned.

Example

var
  S1: String;
  S2: String;
begin
  S1:='Today we are testing copying';
  S2:=Copy(S1,10,3);
  ShowMessage(S2);
end;

Rules to understand the script can be found here.

The text 'Today we are testing copying' is assigned to the string variable S1. The COPY function picks 3 characters from this text from position 14 and assigns this text to variable S2. The new text is output via ShowMessage.

ShowMessage shows: are