Skip to main content
deleted 31 characters in body
Source Link
user3439894
  • 59.8k
  • 10
  • 112
  • 135

Here is a simple handler that, pads based on your question.

Example AppleScript code:

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"

Result: "0001"

 

As a demo, this creates and displays a list of the padded numbers between 0 and 1000 to show the padding is taking place.

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

Here is a simple handler that, pads based on your question.

Example AppleScript code:

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"

As a demo, this creates and displays a list of the padded numbers between 0 and 1000 to show the padding is taking place.

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

Here is a simple handler that, pads based on your question.

Example AppleScript code:

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"

 

As a demo, this creates and displays a list of the padded numbers between 0 and 1000 to show the padding is taking place.

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
added 683 characters in body
Source Link
user3439894
  • 59.8k
  • 10
  • 112
  • 135

Here is a simple handler that, pads based on your question.

Example AppleScript code:

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"

As a demo, this creates and displays a list of the padded numbers between 0 and 1000 to show the padding is taking place.

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

Here is a simple handler that, pads based on your question.

Example AppleScript code:

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"

Here is a simple handler that, pads based on your question.

Example AppleScript code:

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"

As a demo, this creates and displays a list of the padded numbers between 0 and 1000 to show the padding is taking place.

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
Source Link
user3439894
  • 59.8k
  • 10
  • 112
  • 135

Here is a simple handler that, pads based on your question.

Example AppleScript code:

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"