Suppose we create a string like

00025
00026
00027

We don’t have to use an autocounter

We have incremental numbers.

We transform it into a string

Integer iCounter = Integer.valueof(sCounter);
iCounter ++;
        
sCounter = String.valueOf(iCounter );

we will have a similar result to

26
27

Now we want to create a 5-character string where on the left we have zeros

sCounter.leftPad(5, '0')

Apex Guide leftPad