文本文件的操作,急用!(100分)

  • 主题发起人 主题发起人 ifcansee
  • 开始时间 开始时间
I

ifcansee

Unregistered / Unconfirmed
GUEST, unregistred user!
文本文件中有这样的一些字符段
REPORT 3 : ORIGINATING OUTGOING (OROG) TRAFFIC
DATE OF ISSUE: 2003-04-08
RECORD PERIOD: 00:00 - 24:00
OUTPUT PERIOD: 01:00 - 02:00
MSTID :
----------------------------------------------------------------------
-OFFERED CALLS-
total 157 100% 100%
intentions 157 100
injections 0 0
retries 0 0
-SUCCESSFUL CALLS-
answer 108 69
no answer clf 38 24
no answer frl 7 4
called busy 0 0
-LOST CALLS-
reject by inw 0 0
reject due to inw tm 0 0
reject for nm rtg cntl 0 0
reject overload 0 0
continuity check fail 0 0
congestion distant 0 0
frl distant 0 0
invc distant 1 1
not accepted 0 0
not assigned 0 0
other fail 0 0
partial dial clf 4 3
partial dial frl 0 0
redirected 0 0
reject no alternate route 0 0
sender busy 0 0
dsn blocked 0 0
-ADDITIONAL INFO-
inw request accesses 0
inw notify accesses 0
occupancy (erl) 2,92
conversation occupancy (erl) 2,44
avg hold time (secs) 68
avg conv time(secs) 81

如何把他们从该文件中扫描出来然后保存到另外的一个文本文件中,分数不多了,请帮忙啊!

注:这样的字符段落行数相等,而且都是以
REPORT 3 : ORIGINATING OUTGOING (OROG) TRAFFIC
开头的
 
格式确定的话,自己用POS定位每个字段的位置。
 
用tliststring
一行一行读
 
注:这样的字符段落行数相等 ,行數為 itemCount
var
slStr: TStringList;
slSave: tstringList;
i,j: integer;
begin
slStr:= TstringList.create;
slSave:= TstringList.create;
slStr.loadfromFile('文件名稱');
for i:= 0 to slStr.Count-1 do
if trim(slStr.string)='REPORT 3 : ORIGINATING OUTGOING (OROG) TRAFFIC' then
for j:= 0 to itemCount-1 do
slSave.add(slStr.string[i+j]);
slSave.SaveToFile('保存的文件名稱');
end;
 
var
f1,f2:textfile;
s:string;
i:integer;
begin
AssignFile(f1, 'c:/源文件.txt');
Reset(f1);
AssignFile(f2, 'c:/新文件.txt');
Rewrite(f2);

while not eof(f1) do
begin
readln(f1,s);
if s='REPORT 3 : ORIGINATING OUTGOING (OROG) TRAFFIC'
then
begin
writeln(f2,s);
for i:=1 to 你要的行数-1 do
begin
readln(f1,s);
writeln(f2,s);
end;
end;
end;

closefile(f1);
closefile(f2);
end;
 
yck的方法比較穩妥
 
多人接受答案了。
 
后退
顶部