IStringList.BinarySearchRange

Syntax

BinarySearchRange(Value: String; Index: Integer; Count: Integer): Integer;

Parameters

Value. Value that should be found.

Index. Initial index of the range, in which the search is performed.

Count. Number of the elements that are used in search.

Description

The BinarySearchRange method executes binary search of the element in array range.

Comments

Search is executed in the sorted array range. In case of successful search it returns number of the first found element, otherwise it returns -1.

Example

Sub UserProc;
Var
    StrL: IStringList;
    i: Integer;
Begin
    StrL := New StringList.Create;
    For i := 0 To 100 Do
        StrL.Add("Number " + Math.RandBetweenI(0100).ToString);
    End For;
    StrL.Sort;
    i := StrL.BinarySearchRange("Number 20"10, StrL.Count);
End Sub UserProc;

After executing the example a dynamic array of strings is generated. In the midsection of the array, except for the first and last 10 elements, the 20 value is searched. In case of successful search, the "i" variable contains number of the first found element.

See also:

IStringList