ruby的字符串

作者: 孤独的猫
发布时间:2015-07-13 11:31:30

类似于C,一般用'\'作为转义字符

如'escape using "\\"'  将显示  escape using "\"

   'That\'s right'  显示 That's right

 

#{expr}序列把任何Ruby代码的值放入字符串中

"Seconds/day: #{24*60*60}" 得到  Seconds/day: 86400

"#{'Ho!   '*3'}Merry Christmas!" 得到  "Ho! Ho! Ho! Merry Christmas!" 

"This is line #$."  得到  This is line 3

 

进行插入替换的可以是一条或多条语句,如:

irb(main):007:0> puts "now is #{def the(a)
irb(main):008:0"     'the '+a
irb(main):009:0"    end
irb(main):010:0"     the('time')
irb(main):011:0"   }for all good..."
now is the timefor all good...
=> nil
irb(main):012:0>

标签: Ruby
来源:http://www.cnblogs.com/djcsch2001/archive/2012/03/24/2415970

推荐: