Delphi StringBuilder

后端 未结 7 1714
别那么骄傲
别那么骄傲 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条回答
  • 2021-02-12 13:16

    Yes, Delphi offers TStringBuilder (since version 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;
    

    And yes, you are right. s := s + 'text'; isn't really slower than using TStringBuilder.

    0 讨论(0)
提交回复
热议问题