[fpc-pascal]Word count function

Lee, John LeeJ at logica.com
Thu Sep 6 14:36:12 CEST 2001


here is a noddy proc to count words, sort of based on the 4dos word
function. Seems to work for me. HTH. J

this is 4dos word function description...
@WORD[["xxx",]n,string]:  Returns the nth word in a string.  The first word
is numbered 0.  If n is negative, words are returned from the end of the
string.  The first argument is a list of word separators you want to use; if
you don't specify it, only spaces, tabs, and commas are considered to be
word separators.

{ as in 4dos}
function word(delim:string; no:longint;l:string):string;
var n,ll,ul,ct:longint;

begin
if delim='' then delim:=' ,';

ct:=0;
ll:=0;
ul:=0;

n:=1;
repeat

if pos(l[n],delim)>0 then
begin
  ct:=ct+1;

  if ct=no+1 
  then 
    ul:=n
  else
  if ct=no then
   ll:=n;
if deb=1 then writeln('ct n ll ul no ln ',ct,' ',n,' ',ll,' ',ul,' ',no,'
',l[n]);
if deb=1 then writeln('l=',l);
end;

n:=n+1;

until ( (ct=no+1) or (n>length(l)) ) ;

word:=copy(l,ll+1,ul-ll-1);

end;{word}


-----Original Message-----
From: James_Wilson at i2.com [mailto:James_Wilson at i2.com]
Sent: Thursday, September 06, 2001 01:08
To: fpc-pascal at lists.freepascal.org
Subject: [fpc-pascal]Word count function



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
efficient or accurate. I've check the Contributed Units page, but I don't
see anything that looks like it might help me. I also checked the sources
that come with FPC, but unless I'm missing something obvious (which is
possible) I don't see anything their either.

Any help would be appreciated. TIA...

Jim


_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal




More information about the fpc-pascal mailing list