IStringList.BinarySearch

Syntax

BinarySearch(Value: String): Integer;

Parameters

Value. Value that should be found.

Description

The BinarySearch method executes binary search of elements in array.

Comments

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.

Example

Sub Main;

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 Main;

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 number of the first found element.

See also:

IStringList