11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Caché</strong> <strong>ObjectScript</strong> FunctionsDescription$LISTFIND searches the specified list for the first instance of the requested value. The searchbegins with the element after the position indicated by the startafter parameter. If you omitthe startafter parameter, $LISTFIND assumes a startafter value of 0 and starts the searchwith the first element (element 1). If the value is found, $LISTFIND returns the position ofthe matching element. If the value is not found, $LISTFIND returns a 0. The $LISTFINDfunction will also return a 0 if the value of the startafter parameter refers to a nonexistent listmember.ExamplesThe following example returns 2, the position of the first occurrence of the requested string:SET X=$LISTBUILD("A","B","C","D")WRITE $LISTFIND(X,"B")The following example returns 0, indicating the requested string was not found:SET X=$LISTBUILD("A","B","C","D")WRITE $LISTFIND(X,"E")The following examples show the effect of using the startafter parameter. The first exampledoes not find the requested string and returns 0 because it occurs at the startafter position:SET X=$LISTBUILD("A","B","C","D")WRITE $LISTFIND(X,"B",2)The second example finds the second occurrence of the requested string and returns 4, becausethe first occurs before the startafter position:SET Y=$LISTBUILD("A","B","C","A")WRITE $LISTFIND(Y,"A",2)The $LISTFIND function only matches complete elements. Thus, the following examplereturns 0 because no element of the list is equal to the string “B”, though all of the elementscontain “B”:SET mylist = $LISTBUILD("ABC","BCD","BBB")WRITE $LISTFIND(mylist,"B")NotesInvalid Parameter ValuesIf the expression in the list parameter does not evaluate to a valid list, a error occurs.SET x=$CHAR(0,0,0,1,16,27,134,240)SET a=$LISTFIND(x,1) // generates a error250 <strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!