Siebel eScript Language Reference > Siebel eScript Commands > Clib Object Uncategorized Methods >
Clib.bsearch() Method
This method looks for an array variable that matches a specified item. Syntax
Clib.bsearch(key, arrayToSort, [elementCount,] compareFunction)
|
|
key |
The value to be searched |
arrayToSort |
The name of the array to search |
elementCount |
The number of array elements to search; if omitted, the entire array is searched |
compareFunction |
A user-defined function that can affect the sort order |
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 parameter and a variable from the array as its second parameter. 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
Clib.qsort() Method
|