|
发表于 2020-3-23 21:00:02
|
显示全部楼层
procedure TForm1.Button1Click(Sender: TObject);
var
SL : TStringList;
I,K: Integer;
str: string;
begin
SL := TStringList.Create;
{ 原文本位于程序目录下的b.txt }
SL.LoadFromFile(sysutils.ExtractFilePath(application.ExeName)+'b.txt');
{以下是把S4相同的删除余一行}
for I := SL.Count-1 downto 0 do
begin
Str := SL[I];
for K := 1 to 3 do
Str := Copy(Str,pos(',',Str)+1,MAXINT);
Str := Copy(Str,1,Pos(',',Str)-1);
SL[I] := Str + ',' + SL[I];
end;
SL.Sort;
str := Copy(SL[SL.count-1],1,pos(',',SL[SL.count-1])-1);
SL[SL.count-1] := Copy(SL[SL.count-1],pos(',',SL[SL.count-1])+1,MAXINT);
for I := SL.Count-2 downto 0 do
begin
if Copy(SL[I],1,pos(',',SL[I])-1) = Str then
SL.Delete(I)
else
begin
str := Copy(SL[I],1,pos(',',SL[I])-1);
SL[I] := Copy(SL[I],pos(',',SL[I])+1,MAXINT);
end;
end;
{以下是把S5相同的删除余一行}
for I := SL.Count-1 downto 0 do
begin
Str := SL[I];
for K := 1 to 4 do
Str := Copy(Str,pos(',',Str)+1,MAXINT);
SL[I] := Str + ',' + SL[I];
end;
SL.Sort;
str := Copy(SL[SL.count-1],1,pos(',',SL[SL.count-1])-1);
SL[SL.count-1] := Copy(SL[SL.count-1],pos(',',SL[SL.count-1])+1,MAXINT);
for I := SL.Count-2 downto 0 do
begin
if Copy(SL[I],1,pos(',',SL[I])-1) = Str then
SL.Delete(I)
else
begin
str := Copy(SL[I],1,pos(',',SL[I])-1);
SL[I] := Copy(SL[I],pos(',',SL[I])+1,MAXINT);
end;
end;
{全部整理完毕,结果存在程序目录下的 bb.txt }
SL.SaveToFile(sysutils.ExtractFilePath(application.ExeName)+'bb.txt');
SL.Free;
end; |
|