1. Home
  2. Computing & Technology
  3. Delphi Programming

How to get the number of words in Richedit

By , About.com Guide

Here's a code to retrieve the number or words in a RichEdit component:

~~~~~~~~~~~~~~~~~~~~~~~~~
function GetIsWord: boolean;
  var s: string; {presume no word>255 chars}
      c: char;
begin
  result:= false;
  s:= ' ';
  while not eof(f) do
         begin
         read(f, c) ;
         if not (c in ['a'..'z','A'..'Z'{,... etc}]) then break;
         s:=s+c;
         end;
  result:= (s <>' ') ;
end;

procedure GetWordCount(TextFile: string) ;
begin
   Count:= 0;
   assignfile(f, TextFile) ;
   reset(f) ;
   while not eof(f) do
     if GetIsWord then inc(Count) ;
   closefile(f) ;
end;

~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» How to detect when a TMediaPlayer stops playing
« Retrieving a list of installed Applications on Windows

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2002 Delphi Tips
  7. How to get the number of words in Richedit

©2009 About.com, a part of The New York Times Company.

All rights reserved.