procedure TForm1.BitBtn6Click(Sender: TObject); var FileName : TextFile; Str,Tmp : String; TStrList : TStringList; i,k : Integer; begin TStrList := TStringList.Create; TStrList.Clear; if not (FileExists(GetNameDir(Application.ExeName)+'xuanhao.txt')) then begin Application.MessageBox('xuanhao.txt文件不存在,请先转出TXT文件','提示',MB_OK+MB_ICONSTOP); Exit; end; AssignFile(FileName,GetNameDir(Application.ExeName) + 'xuanhao.txt'); Reset(FileName); Readln(FileName,Str); CloseFile(FileName); if Str <> '' then begin i := pos(',',str); while i > 0 do begin Tmp := copy(Str,1,i - 1); TStrList.Add(Tmp); Str := copy(Str,i + 1,length(Str)-i); i := pos(',',Str); end; if Str <> '' then begin TStrList.Add(Str); end; end;
以前也做过一个类似的,我是逐个读取字符,希望对你有帮助 AssignFile(fF1,文件名称); ReSet(fF1); while not EOF(fF1) do begin READ(fF1,cTmpChar); 逐个读取字符进行操作 end;
好像是这个方法我也记不清了你再试一下。
assignfile(f,文件名)
reset(f)seek(f,i)
read(f,a)
var
FileName : TextFile;
Str,Tmp : String;
TStrList : TStringList;
i,k : Integer;
begin
TStrList := TStringList.Create;
TStrList.Clear;
if not (FileExists(GetNameDir(Application.ExeName)+'xuanhao.txt')) then
begin
Application.MessageBox('xuanhao.txt文件不存在,请先转出TXT文件','提示',MB_OK+MB_ICONSTOP);
Exit;
end;
AssignFile(FileName,GetNameDir(Application.ExeName) + 'xuanhao.txt');
Reset(FileName);
Readln(FileName,Str);
CloseFile(FileName);
if Str <> '' then
begin
i := pos(',',str);
while i > 0 do
begin
Tmp := copy(Str,1,i - 1);
TStrList.Add(Tmp);
Str := copy(Str,i + 1,length(Str)-i);
i := pos(',',Str);
end;
if Str <> '' then
begin
TStrList.Add(Str);
end;
end;
AssignFile(fF1,文件名称);
ReSet(fF1);
while not EOF(fF1) do
begin
READ(fF1,cTmpChar);
逐个读取字符进行操作
end;