TStringList.IndexOf

From Soldat Community Wiki
Jump to: navigation, search
function IndexOf(const S: String): Integer
 S: string to be found
 Result: index of S in a TStringList if it has been found, -1 otherwise

Description

The function returns the position of S if it is found in the list, or -1 if the string is not found in the list. Search is case-insensitive.

Example

var
  s: TStringList;
  i: integer;

begin
  s := File.CreateStringList();
  s.Append('a'); // index 0
  s.Append('b'); // index 1
  s.Append('d'); // index 2

  i := s.IndexOf('b'); 
  // i = 1

  i := s.IndexOf('c'); 
  // i = -1

  s.Free;
end.