listLen

Determines the number of elements in a list.

listLen(list [, delimiters, [includeEmptyValues]]) → returns Numeric

Argument Reference for the listLen function

list

Required: Yes
A list or a variable that contains one

delimiters

Required: No
Default: ,
A string or a variable that contains one. Characters that separate list elements. The default value is comma. If this parameter contains more than one character, ColdFusion processes each occurrence of each character as a delimiter. Values:
  • ,
  • |
  • ;
  • chr(9)
  • chr(10)
  • chr(13)

includeEmptyValues

Required: No
Default: NO
CF 10+ If includeEmptyValues is set to true, all empty values in the list will be considered when computing length. If set to false, the empty list elements are ignored.

Examples sample code invoking the listLen function


Simple listLen Example

Get the number of elements in this list

listLen("foo,bar,bar2,foo2")

Expected Result: 4


listLen Example with Delimiter

Get the number of elements in this list using a custom delimiter

listLen("foo,bar|bar2|foo2", "|")

Expected Result: 3


listLen Example with IncludeEmptyValues

Get the number of elements in this list, including empty values

listLen("foo,bar,,foo2", ",", "YES")

Expected Result: 4


Fork me on GitHub