我有一个文本文件disp1.txt(不停更新),里边的内容如下:
1040200394
DPLI|DPHC|DPMB|DPVALOT|
1|1|92|85|3|0|
1|2|2|2|0|0|
2|1|40|30|7|0|
2|2|2|1|1|0|我现在要想取出第三行“1|1|92|85|3|0|”中92、85、3三个不停变化的值,传给我的
程序里的三个变量int a,b,c;
请高手贴出代码。
谢谢。
1040200394
DPLI|DPHC|DPMB|DPVALOT|
1|1|92|85|3|0|
1|2|2|2|0|0|
2|1|40|30|7|0|
2|2|2|1|1|0|我现在要想取出第三行“1|1|92|85|3|0|”中92、85、3三个不停变化的值,传给我的
程序里的三个变量int a,b,c;
请高手贴出代码。
谢谢。
var
rs:string;
fn:textfile;
begin
assignfile(fn,'disp1.txt');
reset(fn);
readln(fn,rs); readln(fn,rs);readln(fn,rs);
edit1.Text:=rs;
closefile(fn);
edit2.Text:=copy(rs,5,2);
edit3.Text:=copy(rs,8,2);
edit4.Text:=copy(rs,11,1);
end;
不行,我给的“1|1|92|85|3|0|”只是一个例子,要是变成“1|1|920|850|300|0|”怎么办呢?(实际上数据是不停变化的,只是格式以"|"分开不变,不能copy吧,那样就错了),有没有更好的办法呢?
谢谢.
Memo1.Clear
Memo1.lines.LoadFormFile(yourFileName);
Text_youwant:=Memo1.line(3);
然后就可以处理了你要设置一个timer就可以了
temp:string;
.......
edit1.Text:=rs;
closefile(fn);
temp:=rs;
temp:=copy(rs,5,length(temp)-5);
edit2.Text:=copy(rs,1,pos('|',temp)-1);
temp:=copy(temp,pos('|',temp),length(temp)-pos('|',temp));
edit3.Text:=copy(rs,1,pos('|',temp)-1);
temp:=copy(temp,pos('|',temp),length(temp)-pos('|',temp));
edit4.Text:=copy(rs,11,1);