Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

ruby string format

time    = 5
message = "Processing of the data has finished in %d seconds" % [time]
puts message
Output => "Processing of the data has finished in 5 seconds"

score = 78.5431
puts "The average is %0.2f" % [score]
Output => The average is 78.54

puts "122 in HEX is %x" % [122]
Output => 122 in HEX is 7a

puts "The number is %04d" % [20]
Output => The number is 0020

names_with_ages = [["john", 20], ["peter", 30], ["david", 40], ["angel", 24]]
names_with_ages.each { |name, age| puts name.ljust(10) + age.to_s }
# Prints the following table
john      20
david     30
peter     40
angel     24
Source by www.rubyguides.com #
 
PREVIOUS NEXT
Tagged: #ruby #string #format
ADD COMMENT
Topic
Name
7+9 =