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

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

From: Ken Shmidheiser <k.shmidheiser@...>
Date: Mon, 25 Feb 2002 07:14:23 -0500
-bowerbird asked:

>you remember that
>challenge we had a while back,
>for a word-counter
>
>i couldn't port jay's fb3-based winner back to fb2.
>
>so who was the winning fb2-compatible winner
>(i hope there was one.)  and where can i get the code
>
>heck, i'll take anyone's code, even if they weren't a winner,
>it would be hard to be much slower than my routines...

-bb,

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.

All the new, fast routines in the Rosetta Stone are written in FB^3. 
One uses a container to hold and count words in up to 2 gigs of text!

Ken

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

   LONG IF countText$ = "" OR delimiter$ = ""
     counter% = 0
     GOTO "exit"
   END IF

   maxPos%  = LEN( countText$ )
   newPos%  = 1
   counter% = 1

   WHILE ( newPos% < maxPos% ) AND ( newPos% <> 0 )
     newPos% = INSTR( newPos%, countText$, delimiter$ )
     LONG IF newPos% <> 0
       counter% = counter% + 1
       newPos% = newPos% + 1
     END IF
   WEND

   "exit"

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