Reputation: 2330
How i can increase an integer start with zeros 00000000, 00000001 , 00000002 ... etc.
var
i:Integer;
begin
i := 00000000;
Inc(i);
ShowMessage(IntToStr(i));
The problem is the inc procedure will trim the zeros on the left.
Output:
1
Not 00000001.
Upvotes: -1
Views: 3004
Reputation: 11
Try this - only one step after Format() -
for i := 1 to NeedLeadingZeros do begin if (Result[i] <> ' ') then break; Result[i] := '0'; end;
Upvotes: 1
Reputation: 12587
As @Sir Rufo wrote it is only matter of formatting and probably you are looking for SysUtils.Format
// SysUtils should be in uses;
...
const
DesiredLen = 8;
var
i:Integer;
begin
i := 0;
Inc(i);
ShowMessage(SysUtils.Format('%.*d', [DesiredLen, i]))
Upvotes: 12