Memo1为可输入对象,如何对Mome1的内如以"逗号"统计出对象出现的次数?例如:
01,03,05,01,06,08,06,12统计出结果如下形式:
================================
01出现了2次;06出现了2次;
03出现了1次;
05出现了1次;
08出现了1次;
12出现了1次
...统计delphi

解决方案 »

  1.   


    var
      tmpList,sumList : TStringList;
      I,tmpInd : Integer;
    begin
      tmpList := TStringList.Create;
      sumList := TStringList.Create;
      tmpList.Clear;
      tmpList.CommaText := '01,03,05,01,06,08,06,12';
      for I := 0 to tmpList.Count - 1 do begin
        tmpInd := sumList.IndexOfName(tmpList[I]);
        if tmpInd  = -1 then begin
          sumList.Add(tmpList[I] + '=1');
        end else begin
          sumList.Values[tmpList[I]] := sumList.Values[tmpList[I]] + 1;
        end;
      end;
      

  2.   

    执行代码后,没有获得希望得到的结果。请问能否把Mome1.text内容统计结果输出到Mome2去??
      

  3.   

    var  tmpList,sumList : TStringList;
    I,tmpInd : Integer;
    begin
    tmpList := TStringList.Create;
    sumList := TStringList.Create;
    tmpList.Clear;
    tmpList.CommaText := '01,03,05,01,06,08,06,12';
    for I := 0 to tmpList.Count - 1 do begin
    tmpInd := sumList.IndexOfName(tmpList[I]);
    if tmpInd  = -1 then begin
    sumList.Add(tmpList[I] + '=1');
    end else begin
    sumList.Values[tmpList[I]] := inttostr(strtoint(sumList.Values[tmpList[I]]) + 1);
    end;
    memo2.Text := sumList.Text;
    end;
    end;