Link to home
Start Free TrialLog in
Avatar of sprinken
sprinken

asked on

Get the count of the words in a txt/rtf/doc file

The title says what I want? For a text file it's easier to get the word count but how can I do the same thing for a rtf or doc file?

Regards,
Sprinken
Avatar of esoftbg
esoftbg
Flag of Bulgaria image

About a .rtf file :

  - load the file content into a TRichEdit component:

      if OpenDialog1.Execute then
        RichEdit1.Lines.LoadFromFile(OpenDialog1.FileName);

  - set the property:

      RichEdit1.PlainText := True;
     
  -  S :=  RichEdit1.Text; // contains the text without formatting symbols, you may count the words !
ASKER CERTIFIED SOLUTION
Avatar of petoskey-001
petoskey-001

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of a_ais
a_ais

where buy.txt is where the filename will go.

procedure TForm1.Button1Click(Sender: TObject);
begin
  RichEdit1.Lines.LoadFromFile(filename);
  RichEdit1.PlainText := true;
  RichEdit1.Lines.DelimitedText := RichEdit1.Text;
  ShowMessage('You have '+IntToStr(RichEdit1.Lines.Count)+' words.');
end;

end.