Returns the number of characters in a string or elements in an array.
function Length(S): Integer;
int Length( S);
System
In Delphi code, Length returns the number of characters actually used in the string or the number of elements in the array. In C++ code, use the method of the same name on the AnsiString or DynamicArray class.
For single-byte and multibyte strings, Length returns the number of bytes used by the string. For Unicode (WideString) strings, Length returns the number of bytes divided by two.
S is a string- or array-valued expression.
Delphi Examples:
{ The following example uses an edit control, a button, and a label on a form. When the button is clicked, the hexadecimal value of each character in the edit control is displayed in the label. } procedure TForm1.Button1Click(Sender: TObject); var i: Integer; begin Label1.Caption := ''; for i := 1 to Length(Edit1.Text) do begin try Label1.Caption := Label1.Caption + SysUtils.IntToHex(Byte(Edit1.Text[i]),2) + ' '; except Beep; end; end; end;
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|