Caché Basic Reference
ListLength
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   
Search:    

Returns the number of elements in a list.
Synopsis
ListLength(list)
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. The null string ("") is also treated as a valid list.
Description
ListLength returns the number of elements in list. It counts all elements in a list, regardless of whether the element has a data value.
Examples
The following example demonstrates how to use the ListLength function:
myList = ListBuild("Red","Blue","Green","Yellow")
Println ListLength(myList) 'prints 4
 
The following example shows that ListLength counts all list elements:
GapList = ListBuild("Red",, "Green", "Yellow")
UndefVarList = ListBuild("Red",x, "Green", "Yellow")
NullStrList = ListBuild("Red","", "Green", "Yellow")
Println ListLength(GapList)        ' prints 4
Println ListLength(UndefVarList)   ' prints 4
Println ListLength(NullStrList)    ' prints 4
 
The following example shows how ListLength handles the null string and a list containing only a null string element:
Println ListLength("")       '  prints 0
NullList = ListBuild("")
Println ListLength(NullList) '  prints 1
 
See Also