If I have a variable, x, that will sometime be a normal printable string, and sometimes be some random hex data (including unprintable chars), how can I reliably print that will space padding? ex:
def prin开发者_C百科t(x)
puts("%-15s" % x)
end
x = "test"
print(x)
x = Array.new(256) { rand(256) }.pack('c*')
print(x)
def print(x)
puts "%-15s" % [x.inspect]
end
And if you want to get rid of the "..."
:
puts "%-15s" % [x.inspect[1..-2]]
精彩评论