Difference between revisions of "TStringList.IndexOf"

From Soldat Community Wiki
Jump to: navigation, search
(new page)
 
m
 
(2 intermediate revisions by 2 users not shown)
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==
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.
+
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==
 
==Example==

Latest revision as of 12:45, 17 March 2019

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.