Count the number of times the '#' character occurs in a string list?.

How can I count the number of times the '#' character occurs in a string list?.

Thanks
Paul.
LVL 1
pr_wainwrightAsked:
Who is Participating?
 
TNameConnect With a Mentor Commented:
Hi, have a look at this:

procedure TForm1.Button1Click(Sender: TObject);
var
SL:TStringList;
i, idx, c, nr : Integer;
begin
  SL:=TStringList.Create;
  SL.Add('#');
  SL.Add('dfg##gdfhg#js#jsf');
  SL.Add('fhhfh');
  SL.Add('thrthrrtttr#');
  SL.Add('aaaaa# a #a a#');
  SL.Add('thrth');
  SL.Add('ztrtj#');
  nr:=0;
  for i:=0 to SL.Count-1 do begin
    idx:=1;
    while idx <= length(SL[i]) do begin
       if SL[i][idx] = '#' then
         Inc(nr);
       Inc(idx);
    end;
  end;
  ShowMessage('Occurences: '+IntToStr(nr));
end;
0
All Courses

From novice to tech pro — start learning today.