COUNT(), COUNTS()

Top  Previous  Next

 

The COUNT() function counts occurrences of a substring within a string. The COUNTS() function is similar to COUNT() but operates on successive elements of a dynamic array, returning a similarly structured dynamic array of results.

 

 

Format

 

COUNT(string, substring)

COUNTS(string, substring)

 

where

 

stringevaluates to the string in which substrings are to be counted.

 

substringevaluates to the substring to count.

 

 

The COUNT() function counts occurrences of substring within string. Substrings may not overlap, thus

 

S = "ABABABABABAB"

N = COUNT(S, "ABA")

 

sets N to 3.

 

If substring is null, COUNT() returns the length of string.

 

Programs compiled with the $NOCASE.STRINGS compiler directive use case insensitive string comparisons in the COUNT() and COUNTS() functions.

 

 

Example

 

MARKS = COUNT(REC, @FM)

 

This statement counts the field marks in REC.

 

 

See also:

DCOUNT()