|
procedure TForm1.Button1Click (Sender: TObject);
var
SL: TStringList;
I, K: Integer;
str: string;
begin
SL: = TStringList.Create;
{The original text is located in the program directory b.txt}
SL.LoadFromFile (sysutils.ExtractFilePath (application.ExeName) + 'b.txt');
{Following is the same as deleting the remaining line of 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;
{The following is the same as deleting the remaining line of 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;
{Completed all, the result is stored in bb.txt in the program directory}
SL.SaveToFile (sysutils.ExtractFilePath (application.ExeName) + 'bb.txt');
SL.Free;
end; |
|