• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Quickie Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Quickie Question


  • Subject: Re: Quickie Question
  • From: Arthur J Knapp <email@hidden>
  • Date: Sat, 30 Mar 2002 19:00:41 -0500

> Date: Sat, 30 Mar 2002 13:28:54 -0700
> From: Applescript User Kreme <email@hidden>
> Subject: Re: Quickie Question

>> set monthNum to do shell script "date +%m"
>
> One very nice (to me) effect of this is that the month is returned as "03"
> instead of "3."

One simple way to obtain zero-padded numbers in AppleScript is to
use negative indexes in this way:

set x to 3
set y to 33

set z_pad to ("0" & x)'s text -2 thru -1 --> "03"
set z_pad to ("0" & y)'s text -2 thru -1 --> "33"

Which one can then generalize:

on ZeroPad(x, n)

set z to ""
repeat (n - 1) times
set z to z & "0"
end repeat

return (z & x)'s text -n thru -1

end ZeroPad

ZeroPad(3, 2) --> "03"
ZeroPad(3, 5) --> "00003"


> Woohoo :)

Woohoo indeed. ;-)



{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
<mailto:email@hidden>
try
<http://www.lazerware.com/>
on error number -128
end try
}
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Quickie Question
  • Next by Date: Re: Restarting OSX through applescript
  • Previous by thread: Re: Quickie Question
  • Next by thread: Re: Quickie Question
  • Index(es):
    • Date
    • Thread