试试这个
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure Gettxt(s:string;var s1,s2,s3:string);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
txt,txt2:Textfile;
s,s1,s2,s3:string;
begin
assignfile(txt,'d:/1.txt');
assignfile(txt2,'d:/2.txt');
reset(txt);
if FileExists('d:/2.txt') then
append(txt2)
else
rewrite(txt2);
while not eof(txt) do
begin
readln(txt,s);
gettxt(s,s1,s2,s3);
s2:=' ';
writeln(txt2,s1,s2,s3);
end;
closefile(txt);
closefile(txt2);
end;
procedure TForm1.Gettxt(s: string
var s1, s2, s3: string);
var
iLen,iTmp:integer;
begin
s:=trim(s);
iLen := length(s);
iTmp:= pos(' ',s);
s1:=copy(s,1,iTmp);
s:=copy(s,itmp,ilen);
s:=trim(s);
iLen := length(s);
iTmp:= pos(' ',s);
s2:=copy(s,1,iTmp);
s:=copy(s,itmp,ilen);
s3:=trim(s);
end;
end.