Re: Generate 001,002... name increments

Posted by jmutterer on
URL: http://imagej.273.s1.nabble.com/Generate-001-002-name-increments-tp3698075p3698076.html

You can use this pad( ) function :

Jerome.

print (pad(3,5,4));
print (pad(32,5,4));

function pad (a, left, right) {
while (lengthOf(""+a)<left) a="0"+a;
separator=".";
while (lengthOf(""+separator)<=right) separator=separator+"0";
return ""+a+separator;
}



while (lengthOf(""+a)<l) a="0"+a;
print (a);

On 8/30/07, Christophe Leterrier <[hidden email]> wrote:

>
> Hi folks,
>
> I'm programming a macro function that checks if a given file exists and
> if so, automatically iterates the name to avoid overwriting previous
> macro outputs.
>
> Is there a simple way to generate a name suffix with beginning zeros
> like 01,02,03...10,11,12...99 ? I could write a function to transform
> index number into zero-containing suffixes, but I'm wondering if iy
> already exists in the macro language or in Java.
>
> If it does'nt exist, maybe this function could be added to the decimal
> to string d2s() function by adding a second argumnt that specifies the
> number of figures before the coma (the other decimal argument specifying
> the number of decimals after the coma).
>
> something like
>
> a=3
>
> d2s(a,2,0)="03"
> d2s(a,3,4)="003.0000"
>
> or a function "integer to string" that would incorporate such a feature...
>
>
>
> Christophe Leterrier
>