BinarySearch(Value: String): Integer;
Value. Value that should be found.
The BinarySearch method executes binary search of elements in array.
Search is executed in the sorted array. In case of successful search it returns the number of the first found element, otherwise it returns -1.
Sub UserProc;
Var
StrL: IStringList;
i: Integer;
Begin
StrL := New StringList.Create;
For i := 0 To 100 Do
StrL.Add("Number " + Math.RandBetweenI(0, 100).ToString);
End For;
StrL.Sort;
i := StrL.BinarySearch("Number 20");
End Sub UserProc;
After executing the example a dynamic array of strings is generated, and the Number 20 value is searched. In case of successful search, the "i" variable contains the number of the first found element.
See also: