文本文件barcode.txt 中有很多条码比如
103909
103908
103907
103804
103805
103806
103908
1039071对文件进行处理成如下
条码 , 数量103909 , 1
103908 , 2
103907 , 2
103804 , 1
103805 , 1
103806 , 1就是对每个条码出现的次数进行统计2.条码234位表示型号,如果2,3,4位字符完全相同则认为完全相同并进行计数处理方式型号 ,数量 ,条码
039 ,5 ,103909 103908 103907 103908 103907
038 ,3 ,103804 103805 103806
103909
103908
103907
103804
103805
103806
103908
1039071对文件进行处理成如下
条码 , 数量103909 , 1
103908 , 2
103907 , 2
103804 , 1
103805 , 1
103806 , 1就是对每个条码出现的次数进行统计2.条码234位表示型号,如果2,3,4位字符完全相同则认为完全相同并进行计数处理方式型号 ,数量 ,条码
039 ,5 ,103909 103908 103907 103908 103907
038 ,3 ,103804 103805 103806
控件用太多,不会连数组都不知道怎么用吧!好歹也应该知道delphi里面有个TStringList吧!
Code: string;
Count: integer;
pNext; PCodeCount;
end;
PCodeCount = ^TCodeCount;一条一条从文件当中读入,然后查找链表,有该号,就增加Count,没有就增加一个节点。第2体类似。
var
sl: tstrings;
procedure Del2Lines(strList: TStrings);
var
strListTemp: TStrings;
i: Integer;
str: string;
begin
strListTemp := TStringList.Create;
try
for i := 0 to strList.Count - 1 do
begin
str := strList.Strings[i];
if strListTemp.IndexOf(trim(str)) < 0 then
begin
strListTemp.Add(str);
end;
end;
strList.Assign(strListTemp);
finally
strListTemp.Free;
end; end;
procedure Stat(Newsl: Tstrings);
var
i,j,icount: integer;
begin
Newsl.Clear;
//stat
for i:=0 to sl.Count - 1 do
begin
icount:=0;
for j := 0 to sl.Count - 1 do
begin
if sl.Strings[i] = sl.Strings[j] then
icount := icount + 1;
end;
Newsl.Add(sl.Strings[i] + ',' + inttostr(icount));
end;
//delete same lines
Del2Lines(Newsl);
end;
begin
sl := TStringList.Create;
sl.LoadFromFile('C:\Documents and Settings\Administrator\桌面\1.txt');
Stat(Memo2.Lines); //show result
sl.Free;
end;