Adding Occurrences in a Memo

0

I have the following items in a memo:

ns
ns
basica+textura+Al
ns
ns
ns
ns
basica+textura+Al
basica+textura+Al
basica+textura+Al
basica+textura+Al
ns
ns
ns

I would like it to add how many times ns appears. I tried using memo1.Lines.IndexOf('ns'); , but it only brings one occurrence.

I think it fits a loop to the end of the memo, but how do I do that?

    
asked by anonymous 23.06.2016 / 16:11

1 answer

3

Scroll through the memo by comparing the lines to ns

procedure TForm1.Button1Click(Sender: TObject);
Var
  n, i  : Integer;
begin
  i := 0;
  for n := 0 to Memo1.Lines.Count - 1 do
  begin
      if ( memo1.Lines[n] = 'ns' ) then
          Inc( i );
  end;
  ShowMessage('ns foi encontrado ' +  IntToStr( i ) + ' vezes ');
end;
    
23.06.2016 / 17:03