2 回答
TA貢獻1828條經驗 獲得超13個贊
procedure TForm1.Button1Click(Sender: TObject);
var
oritext,aimtext:TextFile;
s,str:string;
str1:string[5];
i,m,n:integer;
begin
i:=1;
assignfile(oritext,'D:\aa.txt');//源文件
reset(oritext);//只讀方式打開
assignfile(aimtext,'D:\bb.txt');//目標文件
Rewrite(aimtext);{追加方式打開。也可以用Rewrite(aimtext),這是創建一個新文件(對于一個已存在的文件,此操作將使原文件被覆蓋)。}
try
while not eof(oritext) do//循環讀取文本
begin
readln(oritext,s);
str:=copy(s,3,4)+'/'+copy(s,7,2)+'/'+copy(s,9,2)+' '
+copy(s,11,2)+':'+copy(s,13,2)+':00 '
+copy(s,16,10)+' 001 00 1 ';
m:=length(inttostr(i));//判斷i為字符串時的長度,決定str1中0的個數
for n:=1 to 5-m do
str1:=str1+'0';
str:=str+str1+inttostr(i);
str1:='';
i:=i+1;
writeln(aimtext,str);
end;
finally
closefile(oritext);
closefile(aimtext);
end;
end;
運行正常,結果為:
2007/06/26 18:59:00 0010165059 001 00 1 00001
2007/06/26 18:59:00 0010173847 001 00 1 00002
2007/06/26 18:59:00 0010185451 001 00 1 00003
2007/06/26 18:59:00 0010112243 001 00 1 00004
2007/06/26 18:59:00 0010165059 001 00 1 00005
2007/06/26 18:59:00 0010173847 001 00 1 00006
2007/06/26 18:59:00 0010185451 001 00 1 00007
2007/06/26 18:59:00 0010112243 001 00 1 00008
2007/06/26 18:59:00 0010165059 001 00 1 00009
2007/06/26 18:59:00 0010173847 001 00 1 00010
2007/06/26 18:59:00 0010185451 001 00 1 00011
2007/06/26 18:59:00 0010112243 001 00 1 00012
TA貢獻1893條經驗 獲得超10個贊
對不起,語言代碼我已經忘的差不多了,雖然我也學的Delphi7。
Delphi中有個函數是提取一個字符串中某幾位字符串的,忘了叫什么了,好象是COPY(),參數忘了。
剩下的就是TXT文件的讀和寫過程了。
你看看教程上字符串操作部分和文件管理部分吧,幫不了你別的了,不好意思。
添加回答
舉報
