Convert Array of ShortInt to String, Delphi

前端 未结 1 376
天涯浪人
天涯浪人 2021-01-27 07:39

I\'m doing the way I learned, that is: with a FOR and taking the Index array one by one, but it is leaving too slow, would otherwise convert it to a String? that leaves quicker?

相关标签:
1条回答
  • 2021-01-27 08:15

    I suspect that your code is slow because it is performing unnecessary reallocations of the string. However, without seeing your code it's hard to be sure.

    Probably the simplest way to code your algorithm is to use TStringBuilder. Whether or not that gives sufficient performance, only you can say.

    sb := TStringBuilder.Create;
    try
      for i := 0 to high(buffer) do
      begin
        sb.Append(IntToStr(buffer[i]));
        if i<high(buffer) then
          sb.Append(',');
      end;
      str := sb.ToString;
    finally
      sb.Free;
    end;
    
    0 讨论(0)
提交回复
热议问题