Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

785 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