Page 1 of 1

Posted: Sun Jul 15, 2001 3:14 am
by BackupUser
Restored from previous forum. Originally posted by wayne1.

;CountWords() procedure counts how many words in text
;string = string to search
;delimeter = character between words usually a space but you can use whatever
;you want

Procedure.l CountWords(string.s,delimeter.s)
DefType.w i,space,n
exitWhile.b=0
i=0:space=0:n=1
delimeter=mid(delimeter,1,1);remove any extra characters
string=StripLead(string);dont count leading spaces
string=StripTrail(string);dont count trailing spaces
string=string+delimeter
While exitWhile -1
space=findstring(string,delimeter,n)
If space = 0
exitWhile=-1
Else
i=i+1:n=space+1
EndIf
Wend
ProcedureReturn i
EndProcedure

s$=" Counting how many words in this sentence. "

q=CountWords(s$," ")
messagerequester("Count the Words","There are " + str(q)+ " words in the sentence.",0)