现有文本文件内容
6 2010-12-22 15:50:01 1 0 1 0
16 2010-12-22 15:50:34 1 0 1 0
6 2010-12-22 15:50:53 1 0 1 0
66 2010-12-23 09:01:52 1 0 1 0
3 2010-12-23 09:04:21 1 0 1 0
3 2010-12-23 09:04:45 1 0 1 0
3 2010-12-23 09:08:24 1 0 1 0
66 2010-12-23 09:10:27 1 0 1 0
3 2010-12-23 09:19:05 1 0 1 0
3 2010-12-23 09:24:54 1 0 1 0
66 2010-12-23 09:25:07 1 0 1 0
4 2010-12-23 09:27:01 1 0 1 0
2 2010-12-23 09:31:09 1 0 1 0
3 2010-12-23 09:31:35 1 0 1 0
怎样读取每行记录到变量里?
如第一行,将 ‘ 6’读到一个int变量里,‘2010-12-22 15:50:01’读到datatime变量里,后面的类似。
6 2010-12-22 15:50:01 1 0 1 0
16 2010-12-22 15:50:34 1 0 1 0
6 2010-12-22 15:50:53 1 0 1 0
66 2010-12-23 09:01:52 1 0 1 0
3 2010-12-23 09:04:21 1 0 1 0
3 2010-12-23 09:04:45 1 0 1 0
3 2010-12-23 09:08:24 1 0 1 0
66 2010-12-23 09:10:27 1 0 1 0
3 2010-12-23 09:19:05 1 0 1 0
3 2010-12-23 09:24:54 1 0 1 0
66 2010-12-23 09:25:07 1 0 1 0
4 2010-12-23 09:27:01 1 0 1 0
2 2010-12-23 09:31:09 1 0 1 0
3 2010-12-23 09:31:35 1 0 1 0
怎样读取每行记录到变量里?
如第一行,将 ‘ 6’读到一个int变量里,‘2010-12-22 15:50:01’读到datatime变量里,后面的类似。
解决方案 »
- 分享:酷狗Krc歌词解析 Delphi版
- 如何把word保存到SQL2005数据库中?
- 如何判斷 dll 中包含了 某個 資源文件?
- 关于TCP/IP直连的困惑,请教。
- DBGrid显示
- 帮忙看一下这段代码
- 国产打印控件中使用的单元DsgnIntf.PAS到那里去找
- 我要泡分了。。。。再泡分之前先散点。。。。。
- 很简单:点击form1.button1 ,弹出from2,仍显示form1;并且,不能对form1 再操作,直到form2执行完。
- 一个没有分的问题,我想问一下为什么我下载的Delphi开发人员指南,看的时候它告诉我说字体有错,便不能看了呢?
- 百度空间如何Post发表章???????
- 团队合作软件都有哪些?
不符合要求的自己修改一下uses StrUtils;type
TRec=record
id:integer;
date:TDateTime;
f1,
f2,
f3,
f4:Integer;
end;procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
s:string;
sRec:array of TRec;
sList:TStringList;
procedure SetF(var F:Integer);
begin
F:=StrToInt(RightStr(s,1));
delete(s,Length(s)-1,2);
end;
begin
sList:=TStringList.Create;
try
sList.LoadFromFile('c:\1.txt');
SetLength(sRec,sList.Count);
for i:=0 to sList.Count-1 do
begin
s:=Trim(sList.Strings[i]);
sRec[i].id:=StrToInt(LeftStr(s,pos(' ',s)-1));
delete(s,1,pos(' ',s));
SetF(sRec[i].f4);
SetF(sRec[i].f3);
SetF(sRec[i].f2);
SetF(sRec[i].f1);
sRec[i].date:=StrToDateTime(s);
end;
finally
sList.Free;
end; {取值测试
for i:=low(sRec) to high(sRec) do
memo1.Lines.Add(IntToStr(sRec[i].id)
+' '+ DateTimeToStr(sRec[i].date)
+' '+IntToStr(sRec[i].f1)
+' '+IntToStr(sRec[i].f2)
+' '+IntToStr(sRec[i].f3)
+' '+IntToStr(sRec[i].f4)); }
end;
linebreak:=' ';
text:=s
unit UMain;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,StrUtils, StdCtrls;type
TRec=record
id:integer;
date:TDateTime;
f1,
f2,
f3,
f4:Integer;
end; TFrmMain = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
FrmMain: TFrmMain; implementation{$R *.dfm}procedure TFrmMain.Button1Click(Sender: TObject);
var
i:integer;
s:string;
sRec:array of TRec;
sList:TStringList;
procedure SetF(var F:Integer);
begin
F:=StrToInt(RightStr(s,1));
delete(s,Length(s)-1,2);
end;
begin
sList:=TStringList.Create;
try
sList.LoadFromFile('.\Test.txt');
SetLength(sRec,sList.Count);
for i:=0 to sList.Count-1 do
begin
s:=Trim(sList.Strings[i]);
sRec[i].id:=StrToInt(LeftStr(s,pos(' ',s)-1));
delete(s,1,pos(' ',s));
SetF(sRec[i].f4); //从后面开始删除,最后保留时间字段
SetF(sRec[i].f3);
SetF(sRec[i].f2);
SetF(sRec[i].f1);
sRec[i].date:=StrToDateTime(s);
end;
finally
sList.Free;
end; {取值测试 }
for i:=low(sRec) to high(sRec) do
memo1.Lines.Add(IntToStr(sRec[i].id)
+' '+ DateTimeToStr(sRec[i].date)
+' '+IntToStr(sRec[i].f1)
+' '+IntToStr(sRec[i].f2)
+' '+IntToStr(sRec[i].f3)
+' '+IntToStr(sRec[i].f4));
end;
end.