Delphi Programming

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

How to get the number of words in Richedit

By Zarko Gajic, About.com

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

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming

About.com Special Features

Delphi Programming

  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.