How to count words in a TRichEdit (Views: 29)
Problem/Question/Abstract: How to count words in a TRichEdit Answer: function GetWord: 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 GetWord then inc(Count); closefile(f); end; |