Bookshelf Home | Contents | Index | Search | PDF |
Siebel eScript Language Reference > Siebel eScript Commands > The Clib Object >
Clib.bsearch() Method
This method looks for an array variable that matches a specified item.
Syntax
Clib.bsearch(key, arrayToSort, [elementCount,] compareFunction)
Returns
An array variable that matches key, returning the variable if found, null if not.
Usage
Clib.bsearch() searches only through array elements with a positive index; array elements with negative indices are ignored.
The compareFunction value must receive the key variable as its first argument and a variable from the array as its second argument. If elementCount is not supplied, then the function searches the entire array.
Example
The following example demonstrates the use of Clib.qsort() and Clib.bsearch() to locate a name and related item in a list:
(general) (ListCompareFunction)
function ListCompareFunction(Item1, Item2)
{
return Clib.strcmpi(Item1[0], Item2[0]);
}(general) (DoListSearch)
function DoListSearch()
// create array of names and favorite food
var list =
{
{"Brent", "salad"},
{"Laura", "cheese" },
{ "Alby", "sugar" },
{ "Jonathan","pad thai" },
{ "Zaza", "grapefruit" },
{ "Jordan", "pizza" }
};
// sort the list
Clib.qsort(list, ListCompareFunction);
var Key = "brent";
// search for the name Brent in the list
var Found = Clib.bsearch(Key, list, ListCompareFunction);
// display name, or not found
if ( Found != null )
TheApplication().RaiseErrorText(Clib.rsprintf
("%s's favorite food is %s\n", Found[0][0],Found[0][1]));
else
TheApplication().RaiseErrorText("Could not find name in list.");
}See Also
Bookshelf Home | Contents | Index | Search | PDF |
Siebel eScript Language Reference Published: 18 April 2003 |