The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



CountWordsHTML


Unit:SDL_htmlsupport
Class: none
Declaration: function CountWordsHTML (InString: string; var OpenHTMLTag: boolean): integer;

The function CountWordsHTML returns the number of words in the string InString. In contrast to CountWords this function does not include HTML tags and resolves any HTML entities before counting the words. Thus it is ideally suited to count words in HTML text.

Words are recognized by using the list of word separators defined in the public constant WordSeps. The minimum required length of a word is two characters.

Upon entry of the function the parameter OpenHTMLTag indicates whether the first words in the string belong to an open HTML tag (which has been opened in a previous string). On return, OpenHTMLTag is set to TRUE if the last word is part of an HTML tag which has not been closed within the string InString. This mechanism allows to correctly process HTML tags which span over several lines.

Example: The following sample code shows a typical application of CountWordsHTML. It opens a file specified via the "open" dialog ODiag1, counts the number of words in the file and displays the number of words using the label Label1:
var
  ATFile   : TextFile;
  cnt      : integer;
  astr     : string;
  OpenHtml : boolean;


begin
cnt := 0;
OpenHtml := false;
if ODiag1.Execute then
  begin
  assignfile (ATFile, ODiag1.FileName);
  reset (ATFile);
  while not eof (ATFile) do
    begin
    readln (ATFile, astr);
    cnt := cnt + CountWordsHTML(astr, OpenHtml);
    end;
  closeFile (ATFile);
  Label1.Caption := IntToStr(cnt);
  end;
end;



Last Update: 2023-Feb-06