COUNTS Function

Counts the number of times a substring occurs in each element of a dynamic array.

Syntax

COUNTS(dynArray, substring)

Syntax Elements

dynArray A DataBasic expression that evaluates to a dynamic array.

substring A DataBasic expression that evaluates to a string.

Return Value

A dynamic array with the same structure as dynArray, but with each element replaced by the number of times substring occurs in that element.

If substring is null, each element is replaced by its length in characters.

Substrings can overlap; for example, substring AA occurs three times in string AAAA.

Note

This behaviour can be modified with the UNIQUE.COUNT compatibility switch option.

Example

ARY = "MMI":@AM:"MCMLXXXVII":@AM:"MCMXCVIII"
NEWARY = COUNTS(ARY, "II")

Sets NEWARY to "0AM1AM2". The third element is 2 because COUNTS matches the overlapping elements.