TStringList.IndexOfName

From Soldat Community Wiki
Revision as of 14:37, 24 August 2013 by Mighty (talk | contribs) (Example)
Jump to: navigation, search
function IndexOfName(Name: string): Integer
 Name: name to be searched
 Result: -1 if not found, index of found name otherwise

Description

IndexOfName searches in the list of strings for a name-value pair with name part Name. If such a pair is found, it returns the index of the pair in the stringlist. If no such pair is found, the function returns -1.
The search is done case-insensitive.

Example

var
  s: TStringList;

begin
  s := File.CreateStringList();
  s.Append('a=1');
  s.Append('b=2');
  s.Append('c=3');
  s.Append('d=4');
  s.Append('e=5');

  WriteLn(s.Strings[1]);         // b=2
  WriteLn(s.Names[1]);           // b
  WriteLn(s.Values[s.Names[1]]); // 2

  WriteLn(inttostr(s.IndexOfName(s.Names[1])));
  // 1
  
  s.Free;
end.