Adding a string to the list and getting its index.

 

Syntax

function TStringList.Add(s: string): integer;

 

Parameters and return values

Parameter

Type

Value

s

string

a string for adding to the list.

 

Function result

A string index. It is not necessary a sequence number as the list can be sorted. A numeration starts with zero.

 

Example


var
  SL: TStringList;
begin
  SL := TStringList.Create;
  SL.Sorted := true;
  
  mLogScript(IntToStr(SL.Add('One')), '');
  mLogScript(IntToStr(SL.Add('Two')), '');
  mLogScript(IntToStr(SL.Add('Three')), '');
 
  mLogScript(SL.Text, '');
  SL.Free;  
end.


Script work result

[22:45:12] (Log "AddMethod"): 0

[22:45:12] (Log "AddMethod"): 1

[22:45:12] (Log "AddMethod"): 1

[22:45:12] (Log "AddMethod"): One

Three

Two

[22:45:12] (Run "AddMethod"): Script operation time: 5 ms

[22:45:12] (Run "AddMethod"): Script done successfully.
 

See also

IntToStr
mLogScript

TStringList.Create

TStringList.Free

TStringList.Text

TStringList.Sorted

Created with the Personal Edition of HelpNDoc: Free Kindle producer