RE:Leer la cantidad de palabrs de un txt
A mi me funciona correctamente. Puse el código así:
{Abro el archivo y cuento sus palabras}
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then begin
Memo1.Lines.LoadFromFile(OpenDialog1.FileName);
Label1.Caption:=IntToStr( WordCount (Memo1.Text));
end;
end;
{Separadores de palabras}
function TForm1.Seps(As_Arg: Char): Boolean;
begin
Seps := As_Arg in
[#0..#$1F, ' ', '.', ',', '?', ':', ';', '(', ')', '/', '\'];
end;
{Función de contar palabras}
function TForm1.WordCount(CText: string): Longint;
var
Ix: Word;
Work_Count: Longint;
begin
Work_Count := 0;
Ix := 1;
while Ix <= Length(CText) do
begin
while (Ix <= Length(CText)) and (Seps(CText[Ix])) do
Inc(Ix);
if Ix <= Length(CText) then
begin
Inc(Work_Count);
while (Ix <= Length(CText)) and (not Seps(CText[Ix])) do
Inc(Ix);
end;
end;
Result := Work_Count;
end;
end.