还是读写文本文件问题(50分)

  • 主题发起人 主题发起人 caoliu
  • 开始时间 开始时间
C

caoliu

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样将"STATUS INBOUND_TRUNK OUTBOUND_TRUNK A_NUMBER"和"This is a Billing File
Billing Date:30/09/2001"过滤掉,写成新文本,它们之间有许多条数据,不只是已下例子的2条
例子如下:

S E03 C01 500
STATUS INBOUND_TRUNK OUTBOUND_TRUNK A_NUMBER
S E03 C03 145000
S E03 C01 500
This is a Billing File
Billing Date:30/09/2001
S E02 C03 5000
S E02 C01 650
 
你的问题是从字符串中删除指定字符串么?

functionRemoveInvalid(what, where: string): string;
var
tstr: string;
begin
tstr:=where;
while pos(what, tstr)>0 do
tstr:=copy(tstr,1,pos(what,tstr)-1) +
copy(tstr,pos(what,tstr)+length(tstr),length(tstr));
Result:=tstr;
end;

用法:
NewStr:=RemoveInvalid('<invalid>','This <invalid> is my string and I wan to
remove the word <invalid>');

 
可以一次读一行数据,然后分析该行数据的合法性,是合法数据则写入另外一个文件,否则
扔掉不管;

要分析数据的合法性必须要知道所有合法数据的共性,如你的例子:

第一个字母为‘S’然后是tab,然后跟三个常规字符....

剩下的工作只有你自己来做了
 
cnldh说的对我是初学的,就是不只道怎么解决这是我的代码:
var
txt1,txt2:TextFile;
head1,head2,head3,head4,head5,head6,head7:string;
head8,head9,head10,head11,head12:string;
str,str1,str2,str3,str4,str5,str6,str7,str8,str9,str10,str11,str12:string;

begin
head1:='Status';
head2:='Inbound_Trunk';
head3:='Outbound_Trunk';
head4:='Dialed_Number';
head5:='Call_Date';
head6:='Call_Start';
head7:='Call_Stop';
head8:='Duration';
head9:='OutTrunkName';
head10:='InTrunkName';
head11:='InGID';
head12:='StopDate';
for i:=0 to (FileListBox1.Items.Count-1) do
begin
assignfile(txt1,FileListBox1.items);
reset(txt1);
assignfile(txt2,'D:/cdr.txt');
if fileExists('D:/cdr.txt') then
append(txt2)
else
rewrite(txt2);
writeln(txt2,head1,head2:14,head3:15,head4:14,head5:10,head6:11,
head7:10,head8:9,head9:13,head10:12,head11:6,head12:9);
while not eof(txt1) do
begin
//str1:='S ';
//read(txt1,str1);
//if str1='S ' then
//begin
readln(txt1,str);
writeln(txt2,str);
//end
// else
// readln(txt1);
// writeln(txt2);
end;
Memo1.Lines.Append('@ '+FileListBox1.items+' "读成功"');
Memo1.Lines.Append('@ '+FileListBox1.items+' "写成功"');
closefile(txt1);
closefile(txt2);
end;
 
我自己以解决掉!
 
接受答案了.
 
后退
顶部