Delphi/CB
•  Greatis •  Security •  AppDatabase •  Utilities •  Visual Basic • .NET •  just4fun
Delphi / C++ Builder
Components, utilities and tips for Delphi and C++ Builder developers
Hot Offer
Save your money!
Featured
Ultimate Pack  hot!
Image Editor  new!
Runtime Fusion
Form Designer
Object Inspector
Print Suite Pro
Commented Image
Delphi Toys
WinDowse
Delphi Bonus
TMS Scripter Studio
Form Designer VB
Form Designer .NET

...get more...
for Delphi.NET, C#, VB.NET
for Delphi VCL, BCB 3-6

News Tips .NET Software VCL Software Partners  

Get RichEdit's word count
Use CountInLine function which describe in a private chapter.
This function carry out word count for one string only.
Calling CountInLine for all lines of document, and you will get total word count of the document.

...
  private
    function CounInLine(Str: string): Integer;
...
procedure TForm1.Button1Click(Sender: TObject);
var
  CountWord, i: Integer;
begin
  CountWord:=0;
  with RichEdit1 do
  begin
    for i:=0 to Lines.Count-1 do
      CountWord:=CountWord+CountInLine(Lines.Strings[i]);
  end;
  Label1.Caption:='Word count = '+IntToStr(CountWord);
end;

function TForm1.CountInLine(Str: string): Integer;
var
  Count,Inter: Integer;
  TimeStr,Symbol: string;
begin
  Symbol:='!@#$%^&*()~[]{}":?<>,.|\/*';
  Count:=0;
  while Length(Str)>0 do
  begin
    if Pos(' ',Str)=1 then Delete(Str,1,1)
    else
    begin
      TimeStr:=Copy(Str,1,Pos(' ',Str)-1);
      try
        Inter:=StrToInt(TimeStr);
        Count:=Count-1;
      except
        on EConvertError do Count:=Count;
      end;
      if (Length(TimeStr)=1) and (Pos(TimeStr,Symbol)<>0) then 
        Count:=Count-1;
      if TimeStr='' then Str:=''
      else Delete(Str,1,Pos(' ',Str)-1);
      Count:=Count+1;
    end;
  end;
  CountInLine:=Count;
end;

For more
Delphi Help

Download source


Our Partner
DevArchive.com
Recommended
just4fun
Useful Resources
Win32.hlp Online
Unix Manual Pages
MegaDetailed.NET
in3steps.com
Newsletters
Subscribe to our news!    Subscribe to our news!


Greatis Software Greatis | Security | AppDatabase | Utilities | Delphi/CB | Visual Basic | .NET | just4fun

Contacts | Add to Favorites | Recommend to a Friend | Privacy Policy | Copyright © 1998-2008 Greatis Software