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

# SetLength

Set length of a string.

## Declaration

Source position: line 0

 procedure SetLength( var S: AStringType; Len: Integer );procedure SetLength( var A: DynArrayType; Len: Integer );

## Description

SetLength sets the length of the string S to Len. S can be an ansistring, a short string or a widestring. For ShortStrings, Len can maximally be 255. For AnsiStrings it can have any value. For AnsiString strings, SetLength \emph{must} be used to set the length of the string.

In the case of a dynamical array A, setlength sets the number of elements. The elements are numbered from index 0, so the count runs from 0 to Len-1. If Zero is specified, the array is cleared.

## Errors

None.

 Length Returns length of a string or array.

## Example

Program Example85;

{ Program to demonstrate the SetLength function. }

Var S : String;

begin
FillChar(S[1],100,#32);
Setlength(S,100);
Writeln ('"',S,'"');
end.