Mirror

Count words in a memo (Views: 100)


Problem/Question/Abstract:

Count words in a memo

Answer:

Insert 1 label, 1 button and 1 memo.

procedure TForm1.Button1Click(Sender: TObject);

  function Palabras(Link: string): integer;
  var
    n: integer;
    befspace: boolean;
  begin
    befspace := FALSE;
    if Link = '' then
      Result := 0
    else
      Result := 1;
    for n := 1 to Length(Link) do
    begin
      if befspace and
        (Link[n] <> ' ') and
        (Link[n] <> #13) and
        (Link[n] <> #10) then
        Inc(Result);

      befspace := (Link[n] = ' ') or
        (Link[n] = #13) or
        (Link[n] = #10);
    end;
  end;

begin
  Label1.caption := IntToStr(Palabras(Memo1.Text));
end;
end;

<< Back to main page