[REBOL] Re: Integer formatting
From: carl::cybercraft::co::nz at: 10-Feb-2006 21:08
On Friday, 10-February-2006 at 11:14:18 Steven White wrote,
>I want to assemble the year, month, and day into a string (YYYYMMDD) to
>use in a file name. The following line almost does it:
>
>print join to-string now/year [to-string now/month to-string now/day]
Try a function something like this...
pad: func [value length char][
join to-string array/initial length - length? to-string value char value
]
That allows padding of numbers as well as other values, thus can be used so...
>> pad 10 4 "0"
== "0010"
>> pad "aa" 4 " "
== " aa"
>> pad 100 2 "0"
== "100"
(That last one shows it doesn't strip characters if the padding's not enough.)
>> join to-string now/year [pad now/month 2 "0" pad now/day 2 "0"]
== "20060211"
Hope that helps.
-- Carl Read.