Length function
Returns length of a string or array.
Declaration
function &Length(S: AStringType): SizeIntDescription
Length returns the length of the string or array
S, which is limited
to 255 for shortstrings. If the string
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 dynamic or static 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
Example: ex36
Program Example36;
{ Program to demonstrate the Length function. }
type
somebytes = array [6..10] of byte;
somewords = array [3..10] of word;
Var
S : String;
I : Integer;
bytes : somebytes;
words : somewords;
begin
S:='';
for i:=1 to 10 do
begin
S:=S+'*';
Writeln (Length(S):2,' : ',s);
end;
Writeln('Bytes : ',length(bytes));
Writeln('Words : ',length(words));
end.An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
