对Memo内容统计出字符出现的次数?

aa20000 2013-06-12 02:26:27
Memo1为可输入对象,如何对Mome1的内如以"逗号"统计出对象出现的次数?

例如:
01,03,05,01,06,08,06,12

统计出结果如下形式:
================================
01出现了2次;06出现了2次;
03出现了1次;
05出现了1次;
08出现了1次;
12出现了1次
...
...全文
108 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
aa20000 2013-06-15
  • 打赏
  • 举报
回复
很好!请问一下统计出来的结果能否横向显示呢?
引用 4 楼 月光 的回复:
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;
月光 2013-06-15
  • 打赏
  • 举报
回复
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;
aa20000 2013-06-12
  • 打赏
  • 举报
回复
执行代码后,没有获得希望得到的结果。 请问能否把Mome1.text内容统计结果输出到Mome2去??
酣酣 2013-06-12
  • 打赏
  • 举报
回复
输出SumList就行了!
酣酣 2013-06-12
  • 打赏
  • 举报
回复

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;

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧