Delphi StringBuilder

后端 未结 7 1716
别那么骄傲
别那么骄傲 2021-02-12 12:26

Exists in Delphi something like the Java or C# StringBuilder? Or Delphi does not need StringBuilder and s := s + \'some string\'; is good expression (mainly in for,

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-12 13:12

    The TStringBuilder mentioned is the way to go. In your specific case concatenation may be fine, but I'd always try the alternative anyway.

    I am creating an EPUB body content xhtml file in memory (Delphi XE) and it was taking so long to produce it that I never once let it finish (about 5 minutes plus before abandoning). This is a real life example combining around 800,000 characters of text. Taking the EXACT same code and directly replacing the s:=s+'' style statements with TStringBuilder.Append statements reduced it to around 3 seconds. To reiterate, there were no logic changes beyond a switch away from concatenation.

提交回复
热议问题