编程论坛
注册
登录
编程论坛
→
Delphi论坛
delphi中txt文档数据读取问题
wsyzcn
发布于 2011-06-14 14:01, 1222 次点击
怎样将txt文档中的数据限量存储在数组中,比如文档第一行是 7890,456 我要将7890存储在一个变量中,456存储在另外一个变量中,然后输出在另一个txt
中。
求高手详解!
4 回复
#2
xiakexing
2011-06-29 10:33
procedure TForm1.Button1Click(Sender: TObject);
var
F:TextFile ;
s:string ;
a:Integer ;
begin
AssignFile(f,'d:\1.txt');
Reset(f);
Readln(f,s);
a:=Pos(',',s);
mmo1.Lines.Add(Copy(s,1,a-1)); //第一个变量
mmo1.Lines.Add(Copy(s,a+1,Length(s)-a));//第二个变量
CloseFile(f);
end;
#3
yuutian
2011-06-29 19:21
这个实现了拆开,并存入另一个txt文件,你可以看看:
procedure tform1.button1click(sender:tobject);
var
f,myfile:textfile;
s,str1,str2:string;
a:integer;
begin
edit1.clear;
edit2.clear;
assignfile(f,'e:\myfl.txt');//将文件myfl.txt和变量f关联起来
reset(f);
readln(f,s);
a:=pos(',',s);//取得字符中的逗号
str1:=copy(s,1,a-1);//取得逗号前面的变量
str2:=copy(s,a+1,length(s)-a);//取得逗号后面的变量
edit1.text:=str1;
edit2.text:=str2;
assignfile(myfile,'e:\myfile.txt');//新建一个myfile.txt文件,并和变量myfile关联起来
rewrite(myfile);
write(myfile,'['+str2+']');//将变量str2中的内容存到新建的myfile.txt文件中
closefile(myfile);
closefile(f);
end;
end.
#4
jwhk
2011-07-01 16:20
牛X
#5
rzsgsj
2011-07-07 16:22
不错哦
1