ruby string format formatting
ruby
Solution
Use string interpolation:
padding = 9
"%s%#{padding}d" %[name, number]
Problem
I have a set of filenames named like the following ``` "file001" "file0001" ... "file002" "file0002" ... ... "file100" "file0100" ... ... ``` The pattern is pretty obvious: ``` name, padded_number ``` So if I wanted to use string formatting for the files in the first column I would just write ``` "%s%3d" %[name, number]" ``` But this hardcodes the padding (3). How can I make it so that I can specify the pad as a variable as well and somehow format the provided integer to use the specified padding?