Solved

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

Posted on 2004-08-17
4
184 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
  • 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now