Difference between revisions of "TStringList.IndexOf"

From Soldat Community Wiki
Jump to: navigation, search
(new page)
 
m
Line 1: Line 1:
 
  '''function IndexOf(const S: String): Integer'''
 
  '''function IndexOf(const S: String): Integer'''
 
   S: string to be found
 
   S: string to be found
   Result: TRUE if ''S'' has been found, FALSE otherwise
+
   Result: index of ''S'' in a [[TStringList]] if it has been found, -1 otherwise
  
 
==Description==
 
==Description==

Revision as of 10:27, 22 August 2016

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.

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.