home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / MBUG / MBUG127.ARC / PARSE.LBR / PARSE.IQC / PARSE.INC
Text File  |  1979-12-31  |  2KB  |  55 lines

  1. (* Functions to extract and count words, etc. in a text string *)
  2. (* requires prior type declarations of AnyStr: string[255] and *)
  3. (* CharSet: set of Char *)
  4.  
  5. function ParseCount(S: AnyStr; Delims: CharSet): Integer;
  6.    var
  7.       I, Count: Integer;
  8.  
  9.    begin
  10.       I := 0;
  11.       Count := 0;
  12.       if Length(S) > 0 then
  13.       repeat
  14.          repeat
  15.             I := I + 1
  16.          until not(S[I] in Delims) or (I = Length(S));
  17.          if not(S[I] in Delims) then
  18.             Count := Count + 1;
  19.          if I < Length(S) then
  20.             repeat
  21.                I := I + 1
  22.             until (I = Length(S)) or (S[I] in Delims);
  23.       until I = Length(S);
  24.       ParseCount := Count;
  25.    end;
  26.  
  27. function ParseStr(S: AnyStr; Delims: CharSet; Num: Integer): AnyStr;
  28.    var
  29.       I, Count: Integer;
  30.       TempStr: AnyStr;
  31.  
  32.    begin
  33.       I := 0;
  34.       Count := 0;
  35.       TempStr := '';
  36.       if Length(S) > 0 then
  37.       while Count < Num do
  38.       begin
  39.          repeat
  40.             I := I + 1
  41.          until not(S[I] in Delims) or (I = Length(S));
  42.          if not(S[I] in Delims) then
  43.             Count := Count + 1;
  44.          if Count < Num then
  45.             repeat
  46.                I := I + 1
  47.             until (I = Length(S)) or (S[I] in Delims);
  48.       end;
  49.       repeat
  50.          TempStr := TempStr + S[I];
  51.          I := I + 1;
  52.       until (S[I] in Delims) or (I > Length(S));
  53.       ParseStr := TempStr;
  54.    end;
  55.