1

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?

In my case it would be a Dynamic Array of ShortInt.

For example, given this input:

[0,20,-15]

I would like the following output:

0,20,-15

1 Answer 1

5

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;
Sign up to request clarification or add additional context in comments.

7 Comments

Sorry return this: %PDF-1.5 %âãÏÓ 43 0 obj <</Linearized 1/L 3016435/O 45/E 1562891/N 2/T 3016048/H [ 479 221]>> endobj 54 0 obj <</DecodeParms<</Columns 5/Predictor 12>>/Filter/FlateDecode/ID[<8BC0AFA464E020A336FE264E96C0FB99><DB35BD3D43DC9E40A3A43FE559A7BFE6>]/Index[43 24]/Info 42 0 R/Length 74/Prev 3016049/Root 44 0 R/Size 67/Type/XRef/W[1 3 1]>>stream hÞbbd```b``Z"O‚ÙÇÁd˜\$Yo}±¹šA$[Xedäo’¿þ†30ÍÙÊIþgÜø À`
@JoseEduardo Presumably you can see what all of the code in my answer and RRUZ's does. If that doesn't do what you want, you need to clarify the question. That said, the %PDF-1.5 string looks like the code is behaving well.
I have in my Array [0,150,30,12, -15, -30 ...], and needed to be passed in the same way, but as a concatenated string, Example: Array [0] = 0; Array [1] = 150; Array [2] = 30; ... Already in the string would need something like this: String = 0,150,30 ... All concatenated, but using for is getting too slow...
@DavidHeffernan, you are right I just check the _LStrFromPCharLen implementation and now I understand what do you mean, I will delete my comments in a few seconds :)
Thank you, for your patience and the help, worked like @David Heffernan me suggested. thank you
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.