Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert MS Word document to a PDF file 9 131
How to build JSON File in Delphi 6 3 92
DBCtrlGrid, Delphi, Scroll 8 82
Delphi Firemonkey send email on Android 1 73
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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