How to count the number of expressions in an html page?

If you need help on how to use the program
Post Reply
fulvio53s03
Posts: 776
Joined: 2007-04-28 05:46:43
Location: Italy

How to count the number of expressions in an html page?

Post by fulvio53s03 »

How to count the number of expressions in a page?
Let me explain: how many times is the word "<script>" contained in an html page?
Thanks! :shaking: :innocent:
antp
Site Admin
Posts: 9712
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Re: How to count the number of expressions in an html page?

Post by antp »

I don't think there is a function ready for that, you have to make a loop, something like this:

Code: Select all

var
  i, c: Integer;
  text, search: string;
begin
  c := 0;
  i := 0;
  text := '... your text where you want to search ...';
  search := '<script>';
  while True do
  begin
    i := Pos(search, text);
    if i = 0 then
      break;
    c := c + 1;
    text := Copy(Text, i + Length(search), Length(text));
  end;
end;
(well of course you can create your own function with it to call it easily)
fulvio53s03
Posts: 776
Joined: 2007-04-28 05:46:43
Location: Italy

Re: How to count the number of expressions in an html page?

Post by fulvio53s03 »

Thanks!
Following your suggestion, I found that a little procedure like the following could be a good and quick solution:
Procedure..........
var
stringa, pulisci_episodi : string;
numero_episodi, length_all_episodi, length_value_puliti: integer;
begin
length_all_episodi := length(Page);
distanzia_episodi :=('<div class="linea_alboita">');
pulisci_episodi := stringreplace(Page, stringa, '');
length_value_puliti := length (page) - length(pulisci_episodi);
numero_episodi := length(stringa);
numero_episodi := length_value_puliti div numero_episodi; //div è la divisione!
Value := '';
end;
where numero_episodi is the number i'm lookin for!
Post Reply