首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

对Memo内容统计出字符出现的次数?该如何解决

2013-06-25 
对Memo内容统计出字符出现的次数?Memo1为可输入对象,如何对Mome1的内如以逗号统计出对象出现的次数?例如

对Memo内容统计出字符出现的次数?
Memo1为可输入对象,如何对Mome1的内如以"逗号"统计出对象出现的次数?

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

统计出结果如下形式:
================================
01出现了2次;06出现了2次;
03出现了1次;
05出现了1次;
08出现了1次;
12出现了1次
... 统计 delphi
[解决办法]


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;

[解决办法]
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;

热点排行