比如str:='ddd,ddd,ddd,dd,d,d,'
怎么判断这个字符串有几个逗号?

解决方案 »

  1.   

    while pos(','str)>0 do
    begin
      str[pos(',',str)]:=a;
      inc(count);
    end;最后的count就是有几个逗号
      

  2.   

    忘了说,一开始count:=0
    原理是,发现一个有逗号的地方就用一个非逗号去代替它(比方说是a)
    再不断循环,当没有逗号的时候pos返回值为不大于0的
      

  3.   

    x:=1;
    d:=0; //逗号個數
    for 1 to lenth(str) do 
    begin
      if copy(str,x,1)=',' then d:=d+1
      x:=x+1;
    end;
    showmessage(floattostr(d));
      

  4.   

    对楼上的笔误调整一下:x:=1;
    d:=0; //逗号個數
    for x=0 to length(str) do 
    begin
      if copy(str,x,1)=',' then d:=d+1
      x:=x+1;
    end;showmessage(Inttostr(d));
      

  5.   

    如果你尋找 ,
    while pos(','string)>0 do
    begin
      str[pos(',',str)]:=a;
      inc(count);
    end;
      

  6.   

    count:=0;
    for i:=1 to length(str) do
      count:=count+integer(str[i]=',');