var s:string;
s:='aa,ab,ac';
问题1: 统计逗号在字符串中出现次数的函数
问题2: 将字符串分割在不同变量中的函数,如分割在一个数组变量中

解决方案 »

  1.   

    1、len:=length(s)
       ss:=stringreplace(s,',',''[rfReplaceAll]); 
       len1:=length(ss)
       len -len1=出现次数
      

  2.   

    1、len:=length(s)
       ss:=stringreplace(s,',','',[rfReplaceAll]); 
       len1:=length(ss)
       len -len1=出现次数
      

  3.   

    function GetDotCount(s: string): Integer;
    var
      TmpS : string;
      Len1,Len2 : Integer;
    begin
      Len1 := Length(s);
      TmpS := StringReplace(s,',','',[rfReplaceAll]);
      Len2 := Length(TmpS);
      Result := Len1-Len2;
    end;
      

  4.   

    procedure TForm1.Button2Click(Sender: TObject);
    var
      s : string;
      StringArray : array of string;
      tmps : string;
      i,j : Integer;
    begin
      s := 'aa,bb,cc';
      len := GetDotCount(s);
      SetLength(StringArray,len+1);
      tmps := s;
      j := 0;
      for i := 1 to Length(s) do
      begin
        if tmps[i]=',' then
        begin
          Inc(j);
        end
        else
        begin
          StringArray[j] := StringArray[j]+tmps[i];
        end;
      end;
    end;
      

  5.   

    不知Delphi有没有相关实现函数?
      

  6.   

    var
      s: string;
      list: TStringList;
      i: integer;
    begin
      s:='aa,ab,ac';  list := TStringList.Create;
      list.Delimiter := ',';
      list.DelimitedText := s;
      for  i := 1 to list.Count do
         Memo1.Lines.Add(list(i));
      list.Free;
    end;
      

  7.   

    len:=length(s)
       ss:=stringreplace(s,',','',[rfReplaceAll]); 
       len1:=length(ss)
       len -len1=出现次数