Oct. 30, 2013
9:13 p.m.
On 30 October 2013 20:55, blake <dsblakewatson@gmail.com> wrote:
Heya, guys--
Converting a Ruby program to Pharo, and one of the things this program does is write a file out by date. The format is "yyyymmdd" (which is my preferred naming convention). In Ruby I have:
"%04d" % d.year + "%02d" % d.month + "%02d" % d.day
Why not "%04d%02d%02d" % [d.year, d.month, d.day] ?
In Smalltalk, the closest I can seem to get to this is:
d year asString, (d monthIndex asString padLeftTo: 2 with: $0), (d dayOfMonth asString padLeftTo: 2 with: $0)
...which seems sort verbose. Anyone have any more elegant solutions?
Chris has already given a near solution. You just need to "select: #isDigit" on the end of his answer to get exactly what you want. frank