请问如何读取一个文本文中的行数??? 请问如何读取一个文本文中的行数??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 tstringlist.loadfromfile();tstringlist.count; var t :TextFile; i :integer;begin assignfile(t, 'c:\1.txt'); Reset(t); while not EOF(t) do inc(i);ShowMessage(Inttostr(i));end; procedure TForm1.Button1Click(Sender: TObject);var FileName: string; function Method1: Integer; begin with TStringList.Create do try LoadFromFile(FileName); Result := Count; finally Free end; end; function Method2: Integer; procedure ProcLine(P: PChar; Count: Integer); begin while Count > 0 do begin if P^ = #10 then Inc(Result); Inc(P); Dec(Count); end; end; var Buffer: PChar; RetLen, Count: Integer; begin Result := 0; with TFileStream.Create(FileName, fmShareDenyNone) do try Count := Size; GetMem(Buffer, 102400); try while Count > 0 do begin RetLen := Read(Buffer^, 102400); ProcLine(Buffer, RetLen); Dec(Count, RetLen); end; finally FreeMem(Buffer); end; finally Free; end; end;var S1, S2: string; Count1, Count2: Integer; StartTime, EndTime: DWORD;begin FileName := 'c:\temp\a.txt'; StartTime := GetTickCount; Count1 := Method1; EndTime := GetTickCount; S1 := Format('Time1: %f, Count: %d', [(EndTime - StartTime)/1000, Count1]); StartTime := GetTickCount; Count2 := Method2; EndTime := GetTickCount; S2 := Format('Time2: %f, Count: %d', [(EndTime - StartTime)/1000, Count2]); Caption := S1 + ';' + S2;end; TStringList.LoadFrom(FileName)TStringList.Count 请问TStringList.LoadFrom(FileName)中的TStringList是什么组件???????? TStringList.LoadFrom(FileName)TStringList.Count这个速度快 还请问高手TStringList.LoadFrom(FileName)中的TStringList是什么组件????????以及如何将该文本一行一行的读出来??????多谢了,我是刚接触delphi,请详细解答,再多谢了!!!!!!!! 我这边测试的是用16M数据的文本,结果是:Time1: 0.81, Count: 712701;Time2: 0.08, Count: 712700 不是组件,是类来的,如果你刚学Delphi就还是找些书看吧,如果你学过其它的语言,你应该知道每个语言都封装了很的功能类,这些需要积累,我也说不清。而且还不如按F1来的快,虽是英文的,但想要学好编程,不管是C++/delphi都好,看英文是必不可少的。 copy_paste(木石三) 给你的测试的那个源码给我好吗?????发到我的email:[email protected]中,万分感谢!!!!!!!! 如何在在二进制文件中查找$6D6F7374这个子串并返回指针的位置 菜鸟请教关于fastreport的简单使用 如何检测网卡和声卡的存在 往TMemoryStream类型的变量中导入记录时出错 text类型字段检索问题,谢谢 关于TreeView的问题!!!!!!!! 高分求教关于窗体的问题 如何得到系统所有进程窗体的句柄(为了使用sendmessage函数) 为什么写入一系列数字(字符串形式)进文本文件,打开却是乱码? 请问哪可下载Delphi6自带的Installshield Express的远东语言包? 如何从一个文本文件生成动态菜单? 登陆设置!
tstringlist.count;
t :TextFile;
i :integer;
begin
assignfile(t, 'c:\1.txt');
Reset(t);
while not EOF(t) do
inc(i);
ShowMessage(Inttostr(i));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
FileName: string; function Method1: Integer;
begin
with TStringList.Create do
try
LoadFromFile(FileName);
Result := Count;
finally
Free
end;
end; function Method2: Integer; procedure ProcLine(P: PChar; Count: Integer);
begin
while Count > 0 do
begin
if P^ = #10 then Inc(Result);
Inc(P);
Dec(Count);
end;
end; var
Buffer: PChar;
RetLen, Count: Integer;
begin
Result := 0;
with TFileStream.Create(FileName, fmShareDenyNone) do
try
Count := Size;
GetMem(Buffer, 102400);
try
while Count > 0 do
begin
RetLen := Read(Buffer^, 102400);
ProcLine(Buffer, RetLen);
Dec(Count, RetLen);
end;
finally
FreeMem(Buffer);
end;
finally
Free;
end;
end;var
S1, S2: string;
Count1, Count2: Integer;
StartTime, EndTime: DWORD;
begin
FileName := 'c:\temp\a.txt';
StartTime := GetTickCount;
Count1 := Method1;
EndTime := GetTickCount;
S1 := Format('Time1: %f, Count: %d', [(EndTime - StartTime)/1000, Count1]);
StartTime := GetTickCount;
Count2 := Method2;
EndTime := GetTickCount;
S2 := Format('Time2: %f, Count: %d', [(EndTime - StartTime)/1000, Count2]);
Caption := S1 + ';' + S2;
end;
TStringList.Count
中的TStringList是什么组件????????
TStringList.Count
这个速度快
中的TStringList是什么组件????????
以及如何将该文本一行一行的读出来??????多谢了,我是刚接触delphi,请详细解答,再多谢了!!!!!!!!