[fpc-pascal]Word count function

Gabor DEAK JAHN djg at tramontana.co.hu
Sat Sep 29 14:04:54 CEST 2001

At 9/6/01 08:07 AM, you wrote:


 > Does anyone know of an efficient method for counting the words in a line of
 > data? I've written a few different functions, none of which were terribly

It just happened that I needed this function myself, and I found two errors
in my pseudo-code. Here it is, corrected:

var state : (insideword, firstseparator, moreseparator)

state := insideword
count := 0
for each character in the string do
   case state of
       increment (count)
       if character is separator then state := moreseparator
                 else state = insideword
       if character is not separator then state := insideword
       if character is separator then state := firstseparator
if state = insideword then increment (count)


Gabor DEAK JAHN -- Budapest, Hungary.
E-mail: djg at tramontana.co.hu

More information about the fpc-pascal mailing list