ruby的字符串

简介: 类似于C,一般用'\'作为转义字符 如'escape using "\\"'  将显示  escape using "\"    'That\'s right'  显示 That's right   #{expr}序列把任何Ruby代码的值放入字符串中 "Seconds/day: #{24...

类似于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>

相关文章
|
4月前
|
Ruby
|
4月前
|
数据安全/隐私保护 Ruby 索引
|
4月前
|
存储 Ruby
|
4月前
|
存储 Ruby
|
7月前
|
存储 Java 测试技术
Ruby 字符串从 1.8 到 2.5 的演变
Ruby 字符串从 1.8 到 2.5 的演变
Ruby 字符串从 1.8 到 2.5 的演变
|
索引 Ruby
【Ruby on Rails全栈课程】2.3 ruby的数据类型--字符串(String)、区间(Range)
1、字符串(String) 字符串是String类的对象。分为单引号字符串和双引号字符串。双引号字符串能支持较多的转义字符以及支持字符串#{}q嵌入变量。实际开发中多用双引号字符串。 (1)字符串嵌入变量用#{ },这个是ruby特有的,经常使用的一个功能。只支持双引号的字符串。
275 0
【Ruby on Rails全栈课程】2.3 ruby的数据类型--字符串(String)、区间(Range)