[futurebasic] word count routine

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2001 : Group Archive : Group : All Groups

From: jonathan <jonnnathan@...>
Date: Fri, 21 Sep 2001 13:01:08 +0200
a word count basically counts spaces and returns.
this doesn't take false possitives from double spaces and multiple returns.

enjoy,
:-j


'----------- start code -----------
local mode
local fn wordCount( theContH as handle)
DIM mySize     as unsigned long
dim myCount    as unsigned long
dim myOffset   as unsigned long
dim myChar     as byte
dim myPrevChar as byte
'
mySize = fn gethandlesize( theContH)
long if( mySize)
// mySize -= 1 : 
myOffset = 1 : myCount = 0 : myPrevChar = 0
while( myOffset < mySize)
myChar = |[theContH] +myOffset|
long if( myChar = &h20)
if((( myPrevChar) and( myPrevChar != myChar)) [+]
    and( myPrevChar != &h0D)) then myCount += 1
xelse
long if( myChar = &h0D)
if((( myPrevChar) and( myPrevChar != myChar)) [+]
   and( myPrevChar != &h20)) then myCount += 1
end if
end if
myPrevChar = myChar
myOffset   += 1
wend
myChar = |[theContH] +mySize -1|
// if doesn't end with return or blank
if(( myChar != &20) and( myChar != &h0D)) [+]
   then myCount += 1
end if

end fn = myCount
'--------------- end code ---------------