Re: Quickie Question
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.