COUNTS function
Syntax
COUNTS (dynamic.array, substring)
CALL -COUNTS (return.array, dynamic.array, substring)
CALL !COUNTS (return.array, dynamic.array, substring)
Description
Use the COUNTS function to count the number of times a substring is repeated in each element of a dynamic array. The result is a new dynamic array whose elements are the counts corresponding to the elements in dynamic.array.
dynamic.array specifies the dynamic array whose elements are to be searched.
substring is an expression that evaluates to the substring to be counted. substring can be a character string, a constant, or a variable.
Each character in an element is matched to substring only once. Therefore, when substring is longer than one character and a match is found, the search continues with the character following the matched substring. No part of the matched element is recounted toward another match.
If substring does not appear in an element, a 0 value is returned. If substring is an empty string, the number of characters in the element is returned. If substring is the null value, the COUNTS function fails and the program terminates with a run-time error message.
If any element in dynamic.array is the null value, null is returned.
If you use the subroutine syntax, the resulting dynamic array is returned as return.array.
PICK, IN2, and REALITY Flavors
In PICK, IN2, and REALITY flavors, the COUNTS function continues the search with the next character regardless of whether it is part of the matched string. Use the COUNT.OVLP option of the $OPTIONS statement to get this behavior in IDEAL and INFORMATION flavor accounts.
Example
ARRAY="A":@VM:"AA":@SM:"AAAAA"
PRINT COUNTS(ARRAY, "A")
PRINT COUNTS(ARRAY, "AA")
This is the program output:
1V2S5
0V1S2