Re: String Functions




"Florent Ouchet" <ouchet.florent@xxxxxxxxxxx> wrote

> There were a IntToStr some months ago:
>
http://groups.google.com/groups?hl=fr&lr=&threadm=41f3fa05%40newsgroups.borland.com&rnum=13&prev=/groups%3Fq%3Dint%2Bgroup:borland.public.delphi.language.basm%26start%3D10%26hl%3Dfr%26lr%3D%26selm%3D41f3fa05%2540newsgroups.borland.com%26rnum%3D13

> This code [IntToStrPLR1 from Pierre le Riche] seems to be fast:
>
http://groups.google.com/groups?hl=fr&lr=&selm=41f3c66f%40newsgroups.borland.com

The following IntToStr_JH1 function seems to be about
4 times faster than IntToStrPLR1 on small integers and
about the same as IntToStrPLR1 on the largest integers.
IntToStrPLR1 seems to be about 2.2 as fast as the RTL
IntToStr. I am running D5 under Win2K.

--JohnH

Function IntToStr_JH1(const Int: integer): string;
var r, i, n: integer; temp: array [0..11] of char; neg: boolean;
begin
neg := (Int < 0);
If neg
then r := -Int
else r := Int;
i := high(temp);
Repeat
temp[i] := char((r mod 10) + ord('0'));
dec(i);
r := r div 10;
Until (r = 0);
If neg
then begin temp[i] := '-'; dec(i) end;
n := high(temp)-i;
SetLength(Result,n);
Move(temp[i+1],Result[1],n);
end; {NOT WELL TESTED}

.