I want to format the output of a string in ruby. I can do it using % but I cannot figure it out.
Instead of 201107070928 I want to output 2011\07\070928
puts "%.4s\\%.2s\\%s" % "201107070928"
gives me an error:`%’: too few arguments (ArgumentError)
I’m going to put this in an answer rather than a comment just because I’m more impressed with the possibility. Using String#unpack, we can handle a 4 digit / 2 digit / anything with: