function IntToStr(Value: Integer): string; begin FmtStr(Result, '%d', [Value]); end; procedure FmtStr(var Result: string; const Format: string; const Args: array of const); var Len, BufLen: Integer; Buffer: array[0..4095] of Char; begin BufLen := SizeOf(Buffer); if Length(Format) < (sizeof(Buffer) - (sizeof(Buffer) div 4)) then Len := FormatBuf(Buffer, sizeof(Buffer) - 1, Pointer(Format)^, Length(Format), Args) else begin BufLen := Length(Format); Len := BufLen; end; if Len >= BufLen - 1 then begin while Len >= BufLen - 1 do begin Inc(BufLen, BufLen); Result := ''; // prevent copying of existing data, for speed SetLength(Result, BufLen); Len := FormatBuf(Pointer(Result)^, BufLen - 1, Pointer(Format)^, Length(Format), Args); end; SetLength(Result, Len); end else SetString(Result, Buffer, Len); end;
实现过程: function IntToStr(Value: Integer): string; begin FmtStr(Result, '%d', [Value]); end; 调用: var s:string; i:integer; begin i:=123; s:=inttostr(i); end;
我很苯 Function MyInttostr(const Int:integer):string; Var d,m:integer; Begin m:=int; Result:=''; while m<>0 do Begin d:=m mod 10; m:=m div 10; Result:=chr(d+48)+Result; end; end;
begin
FmtStr(Result, '%d', [Value]);
end;
procedure FmtStr(var Result: string; const Format: string;
const Args: array of const);
var
Len, BufLen: Integer;
Buffer: array[0..4095] of Char;
begin
BufLen := SizeOf(Buffer);
if Length(Format) < (sizeof(Buffer) - (sizeof(Buffer) div 4)) then
Len := FormatBuf(Buffer, sizeof(Buffer) - 1, Pointer(Format)^, Length(Format), Args)
else
begin
BufLen := Length(Format);
Len := BufLen;
end;
if Len >= BufLen - 1 then
begin
while Len >= BufLen - 1 do
begin
Inc(BufLen, BufLen);
Result := ''; // prevent copying of existing data, for speed
SetLength(Result, BufLen);
Len := FormatBuf(Pointer(Result)^, BufLen - 1, Pointer(Format)^,
Length(Format), Args);
end;
SetLength(Result, Len);
end
else
SetString(Result, Buffer, Len);
end;
function IntToStr(Value: Integer): string;
begin
FmtStr(Result, '%d', [Value]);
end;
调用:
var s:string;
i:integer;
begin
i:=123;
s:=inttostr(i);
end;
Function MyInttostr(const Int:integer):string;
Var d,m:integer;
Begin
m:=int;
Result:='';
while m<>0 do
Begin
d:=m mod 10;
m:=m div 10;
Result:=chr(d+48)+Result;
end;
end;