[futurebasic] re: Re: [FB] text parsing

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : February 2002 : Group Archive : Group : All Groups

From: Jay <jktr@...>
Date: Mon, 25 Feb 02 09:31:52 -0600
>I can't even approach Jay's elegant solution, but here's an old one 
>from the FBII bin for a text string. Should be modifiable to count 
>words in an edit field handle or from a text document. You also might 
>want to experiment with FN MUNGER-- it's fast.
>
BB,

The real winner is FB^3--Use it!

However, here's a modification of the code Ken sent. I don't know whether 
it's faster (it may be), but it is at least more accurate in that it 
won't count "  " as 2 words.

 e-e
 =J= a  y
  "

CLEAR LOCAL MODE
DIM newPos%, prevPos%, maxPos%, counter%
LOCAL FN CountWords( countText$, delimiter$ )

   IF countText$ = "" OR delimiter$ = "" THEN EXIT FN

   maxPos%  = LEN( countText$ )

   DO
     prevPos% = newPos%
     newPos%  = INSTR( prevPos% + 1, countText$, delimiter$ )
     IF newPos% - prevPos% > 1 THEN counter% = counter% + 1
   UNTIL newpos% = 0

   IF maxPos% - prevPos% > 1 THEN counter% = counter% + 1

END FN = counter%

WINDOW 1

DIM test$, count%

test$ = "This is a test to see how many words are in this sentence."

count% = FN CountWords( test$, " " )

PRINT:PRINT test$
PRINT:PRINT "There are"; count%; " words in this sentence."
PRINT:PRINT"Click mouse to end."

DO
   HANDLEEVENTS
UNTIL FN BUTTON