Solved

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

Posted on 2004-08-17
4
190 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:sprinken
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 12

Expert Comment

by:esoftbg
ID: 11826708
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 !
0
 
LVL 7

Accepted Solution

by:
petoskey-001 earned 50 total points
ID: 11831972
Or if you like, get this file...
http://jouwfeestje.com/files/fileinfo/

It works with RTF and DOC files.  Freeware, with source.  It gives you much more then your looking for, but it does what you ask.
0
 
LVL 1

Assisted Solution

by:a_ais
a_ais earned 30 total points
ID: 11862861
procedure TForm1.Button1Click(Sender: TObject);
begin
  RichEdit1.Lines.LoadFromFile('c:\buy.txt');
  RichEdit1.PlainText := true;
  RichEdit1.Lines.DelimitedText := RichEdit1.Text;
  ShowMessage('You have '+IntToStr(RichEdit1.Lines.Count)+' words.');
end;

end.
0
 
LVL 1

Expert Comment

by:a_ais
ID: 11862864
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question