- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
delphi 高速替换大文本字符串内容
普通替换:
var
Str: string;
i: Integer;
T1, T2: Integer;
begin
T1 := GetTickCount;
try
for i := 0 to M.Lines.Count - 1 do //M 加载文本得代码省略自己搞
begin
Str := Str + M.Lines[i];
end;
T2 := GetTickCount;
// ShowMessage(Inttostr(T2 - T1));
M.Lines.BeginUpdate;
M.Lines.Text := Str;
finally
M.Lines.EndUpdate;
end;
end;
高速替换:
感谢汗血宝宝分享
TFile IOUtils 单元主要就是三个结构: TDirectory、TPath、TFile,
var
SW: TStopwatch;
s: string;
begin
SW := TStopwatch.StartNew;
s := TFile.ReadAllText('D:\9万行文本.txt',TEncoding.UTF8).Replace(#13#10, '');
TFile.WriteAllText('D:\9万行文本_.txt', s,TEncoding.UTF8);
SW.Stop;
ShowMessage(SW.ElapsedMilliseconds.ToString);
end;
感谢黑夜杀手提供
在提供一个老外得汇编方案:一种高效的自定义字符串替换函数