Ecco un semplice gestore che, pad basati sulla tua domanda.
Codice AppleScript di esempio:
set theNumber to 1
set theNumber to padNumberAsString(theNumber)
on padNumberAsString(n)
set theLength to (get length of (n as string))
if theLength is equal to 1 then
set n to "000" & n
else if theLength is equal to 2 then
set n to "00" & n
else if theLength is equal to 3 then
set n to "0" & n
end if
return n
end padNumberAsString
Result: "0001"
Come demo, questo crea e visualizza un elenco dei numeri riempiti tra 0 e 1000 per mostrare che il padding è in corso.
set thePaddedList to {}
repeat with i from 0 to 1000
set end of thePaddedList to padNumberAsString(i)
end repeat
choose from list thePaddedList
on padNumberAsString(n)
set theLength to (get length of (n as string))
if theLength is equal to 1 then
set n to "000" & n
else if theLength is equal to 2 then
set n to "00" & n
else if theLength is equal to 3 then
set n to "0" & n
end if
return n
end padNumberAsString