Node: Copy, Next: Cos, Previous: Continue, Up: Reference

### Copy

#### Synopsis

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

or

         function Copy (S: String; FirstChar: Integer): String;

#### Description

`Copy` returns a sub-string of `S` starting with the character at position FirstChar. If Count is given, such many characters will be copied into the sub-string. If Count is omitted, the sub-string will range to the end of S.

If `Count` is too large for the sub-string to fit in S, the result will be truncated at the end of S. If `FirstChar` exceeds the length of S, the empty string will be returned. (For a function which does not truncate but triggers a runtime error instead, see SubStr.)

Please note that GPC's strings may be longer than 255 characters. If you want to isolate the second half of a string S starting with the third character, use `Copy (S, 3)` instead of `Copy (S, 3, 255)`.

#### Conforming to

`Copy` is a UCSD Pascal extension. The possibility to omit the third parameter is a GNU Pascal extension.

#### Example

         program CopyDemo;
         var
           S: String (42);
         begin
           S := 'Hello';
           WriteLn (Copy (S, 2, 3));  { yields `ell' }
           WriteLn (Copy (S, 3));     { yields `llo' }
           WriteLn (Copy (S, 4, 7));  { yields `lo' }
           WriteLn (Copy (S, 42))     { yields the empty string }
         end.

#### See also

SubStr, String Slice Access.