请问如何数出test中有多少个'-',test:=aaa-aaaaa-aaa,test是个变量哦

解决方案 »

  1.   

    var
     s:string;
     i,count:integer;
    begin
     count :=0;
     s:='aa-sss-dd-ee';
     for i:=1 to length(s) do
     begin
        if s[i]='-' then count :=count+1;
     end;
     end;
      

  2.   

    var
    tt:tstringlist;
    i:integer;
    test:string;
    begin
      test:='aaa-aaaaa-aaa';
      tt:=tstringlist.create;
      tt.Delimiter:='-';
      tt.DelimitedText:=test;
      for i:=0 to tt.count-1 do    //有tt.count-1个'-'
      begin
          showmessage(tt[i]);
      end;
      tt.free;
    end;
      

  3.   

    var 
      aa:String;
      i,count:integer;
    begin
    for i:=1 to length(s) do
     begin
        if s[i]='-' then 
           count :=count+1;
     end;
     end;