The DCOUNT function returns the number of fields separated by a specified delimiter.
Format
DCOUNT(sourcestring,substring) |
Parameter(s)
sourcestring |
An expression evaluating to the string to be searched. |
substring |
An expression evaluating to the character to be used as a delimiter. If substring evaluates to more than one character, only the first character will be searched for. |
Description
The DCOUNT function returns the number of delimited fields contained within a data string.
DCOUNT differs from COUNT in that it only searches for a single character and returns the number of values separated by the specified substring rather than the number of occurrences of the substring. If the null string is used as the substring, the number of characters in the string is returned. If the string evaluates to the null string, zero (0) is returned. If the substring is not found within the string, a value of 1 is returned.
In most instances the DCOUNT function returns the same value as performing the COUNT function and adding 1. This should not be relied upon, however—note that when performed on the null string (""): DCOUNT returns 0, while COUNT+1 returns 1.
The DCOUNT function is particularly useful for processing dynamic arrays, for example to count the number of attributes within an item.
Example
In this application the DCOUNT function is used to determine the number of attributes and the number of values in a dynamic array. Each individual value of the array may then be displayed with imbedded FOR loops, as if it were a matrix.
NumberOfAttributes=DCOUNT(Record, CHAR(254)) FOR AttributeNumber=1 TO NumberOfAttributes CurrentAttribute=Record<AttributeNumber> NumberOfValues=DCOUNT(CurrentAttribute,CHAR(253)) FOR ValueNumber=1 TO NumberOfValues PRINT CurrentAttribute<1,ValueNumber> NEXT ValueNumber NEXT AttributeNumber |
See Also