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

Length

Returns length of a string.

Declaration

Source position: line 0

function Length(

  S: AStringType

):Integer;

function Length(

  A: DynArrayType

):Integer;

Description

Length returns the length of the string S, which is limited to 255 for shortstrings. If the strings S is empty, 0 is returned.

Note: The length of the string S is stored in S[0] for shortstrings only. The Length function should always be used on ansistrings and widestrings.

For dynamical arrays, the function returns the number of elements in the array.

Length also supports arguments of type PCharand PWideChar, in which case it is identical to the StrLen and WStrLen functions, respectively. In this case, the function actually calculates the length of the null-terminated string, and its execution time is proportional to the string length because the terminating null character is searched through a linear scan.

Errors

None.

See also

Pos

  

Search for substring in a string.

Example

Program Example36;

{ Program to demonstrate the Length function. }

Var S : String;
    I : Integer;

begin
  S:='';
  for i:=1 to 10 do
    begin
    S:=S+'*';
    Writeln (Length(S):2,' : ',s);
    end;
end.
The latest version of this document can be found at lazarus-ccr.sourceforge.net.