Siebel eScript Language Reference > Siebel eScript Commands > The Clib Object Uncategorized Methods >

Clib.bsearch() Method

This method looks for an array variable that matches a specified item.


Clib.bsearch(key, arrayToSort, [elementCount,] compareFunction)



The value to search for


The name of the array to search


The number of array elements to search; if omitted, the entire array is searched


A user-defined function that can affect the sort order


An array variable that matches key, returning the variable if found, null if not.


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.


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 )
      ("%s's favorite food is %s\n", Found[0][0],Found[0][1]));
      TheApplication().RaiseErrorText("Could not find name in list.");

See Also

Clib.qsort() Method

Siebel eScript Language Reference