Skip to main content

ListFind

Finds an element in a list.

Synopsis

ListFind(list,value[,startafter])

Arguments

list An expression that evaluates to a valid list. A Caché list must be created using ListBuild or ListFromString, or extracted from another list using List.
value An expression which evaluates to the value of the element to find.
startafter Optional — An expression interpreted as a list position. The search starts with the element after this position.

Description

The ListFind function searches the specified list for the first instance of the requested value. The search begins with the element after the position indicated by the startafter argument. If you omit the startafter argument, ListFind assumes a startafter value of 0 and starts the search with the first element. If the value is found, ListFind returns the position of the first matching element. If the value is not found, ListFind returns zero (0). The ListFind function will also return a 0 if the value of the startafter argument refers to a nonexistent list member.

The ListFind function only matches complete elements. Thus, the following example returns 0 because no element of the list is equal to the string “B”, though all of the elements contain “B”:

mylist = ListBuild("ABC","BCD","BBB")
Println ListFind(mylist,"B")

Examples

The following example demonstrates how to use the ListFind function:

myList = ListBuild("Red", "Blue", "Green", "Yellow","Green")
Println ListFind(myList,"Green")   ' prints 3
Println ListFind(myList,"Green",3) ' prints 5
Println ListFind(myList,"Red")     ' prints 1
Println ListFind(myList,"Red",1)   ' prints 0 (not found)

See Also

FeedbackOpens in a new tab