MyChat Scripts: function TStringList.IndexOf, searching for string index in the list by exact match
Find a string index by exact match. The letter case does matter.
Syntax
function TStringList.IndexOf(s: string): integer;
Parameters and return values
| Parameter | Type | Value | 
| s | string | string for searching. | 
Example
var
  SL: TStringList;
  i, x, iID: integer;
begin
  SL := TStringList.Create;
  SL.Sorted := true;
  
    for i := 1 to 20 do
      SL.Add(IntToStr(i));
  
  mLogScript(SL.CommaText, 'Sorted by alphabet');
  
    for i := 1 to 5 do begin
      x := random(20);
      iID := SL.IndexOf(IntToStr(x));
      
        if iID <> -1 then mLogScript('position of "' + SL[iID] + '" value is ' + IntToStr(iID), '');
    end;
    
  SL.Free;  
end.
Script work result
[14:55:01] (Log "IndexOfMethod"): [Sorted by alphabet] 1,10,11,12,13,14,15,16,17,18,19,2,20,3,4,5,6,7,8,9
[14:55:01] (Log "IndexOfMethod"): position of "10" value is 1
[14:55:01] (Log "IndexOfMethod"): position of "3" value is 13
[14:55:01] (Log "IndexOfMethod"): position of "15" value is 6
[14:55:01] (Log "IndexOfMethod"): position of "3" value is 13
[14:55:01] (Log "IndexOfMethod"): position of "12" value is 3
[14:55:01] (Run "IndexOfMethod"): Script operation time: 5 ms
[14:55:01] (Run "IndexOfMethod"): Script done successfully.
See also
Created with the Personal Edition of HelpNDoc: Revolutionize your documentation process with HelpNDoc's online capabilities