存在于Delphi中的东西像
Java或C#StringBuilder?或者Delphi不需要StringBuilder和s:= s’some string’;是好的表达(主要是for,while循环).
解决方法
是的,Delphi提供TStringBuilder(自2009版本):
procedure TestStringBuilder; var I: Integer; StringBuilder: TStringBuilder; begin StringBuilder := TStringBuilder.Create; try for I := 1 to 10 do begin StringBuilder.Append('a string '); StringBuilder.Append(66); //add an integer StringBuilder.Append(sLineBreak); //add new line end; OutputWriteLine('Final string builder length: ' + IntToStr(StringBuilder.Length)); finally StringBuilder.Free; end; end;
更多信息(基准):
http://www.monien.net/blog/index.php/2008/10/delphi-2009-tstringbuilder/.
是的,你是对的. s:= s’text’;并不比使用TStringBuilder慢得多.