var f:TxtFile;
s:string;
List:TStringList;//保存你所需的数据
begin
List:=TStringList.create;
AssignFile(f,'c:\test.txt');
if fileexists(f) then
begin
reset(f);
while eof(f) do
begin
readln(f,s);
if pos(',',s)>0 then
begin
List.add(Copy(s,1,pos(',',s)));
delete(s,1,pos(',',s));
end
else
List.add(s);
end;
end;
List.free;
end;
至于如何读取字段记录,可以定义一个数组,
var
FieldValue : Array of String;
setlength(FieldValue,4);
for J := 0 to memo1.lines.count do
begin
tmpstr := memo1.lines[J];
for I := 0 to 3 do
begin
FieldValue[I] := copy(tmpstr,1,pos(',',tmpstr) - 1);
tmpstr := copy(tmpstr,pos(',',tmpstr),length(tmpstr) - pos(',',tmpstr));
end;
end;