dcount() function

The dcount() function returns the number of occurrences of the delimiter specified in str.exp2 within str.exp1, plus one.


dcount(str.exp1, str.exp2)


str.exp1 Specifies the string expression, plus one, in which to search for the delimiter specified in str.exp2.
str.exp2 Specifies the delimiter to locate within str.exp1.


The difference between this function and the count() function is that 1 is added to the result unless the string referenced in str.exp1 is null.


how.many contains the number of attributes in string. In this example, there are 3 and each attribute displays on the terminal in a separate line.

string = "a" : char(254) : "b" : char(254) : "c"
how.many = dcount(string,char(254))
for amc = 1 to how.many
crt string<amc>
next amc

In this example, sentence is entered from the keyboard. The string in sentence is trimmed of excess spaces, and the number of words delimited by spaces is counted using dcount(). The words are then printed on separate lines.

input sentence
sentence = trim(sentence)
maxwords = dcount(sentence,’ ’)
for wordcnt = 1 to maxwords
print field(sentence,’ ’,wordcnt)
next wordcnt