Difference between revisions of "TStringList.IndexOfName"

From Soldat Community Wiki
Jump to: navigation, search
(new page)
 
m (Example)
 
(One intermediate revision by the same user not shown)
Line 20: Line 20:
 
   s.Append('e=5');
 
   s.Append('e=5');
  
   WriteLn(s.Strings[1]);         // b=2
+
   WriteLn(inttostr(s.IndexOfName('b')));
   WriteLn(s.Names[1]);          // b
+
   // 1
  WriteLn(s.Values[s.Names[1]]); // 2
 
 
    
 
    
 
   s.Free;
 
   s.Free;

Latest revision as of 14:38, 24 August 2013

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(inttostr(s.IndexOfName('b')));
  // 1
  
  s.Free;
end.