Ruby编程之字符串拼接
【摘要】 笔者主要用Ruby编写字符串拼接小案例
s1 = "This " << "is" << " a string " << 36 # char 36 is '$'
s2 = "This " + "is" + " a string " + 36.to_s
s3 = "This " "is" " a string " + 36.to_s
puts("(s1):" << s1)
puts("(s2):" << s2)
puts("(s3):" << s3)
(s1):This is a string $
(s2):This is a string 36
(s3):This is a string 36
s4 = "This " , "is" , " not a string!", 10
print("print (s4):" , s4, "\n")
x = "This " , "is" , " not a string!", 36
print("print (x):" , x, "\n")
puts("puts(x):", x)
puts("puts x.class is: " << (x.class).to_s )
print("print(x):" , x, "\n")
puts("puts(x):", x)
puts("puts x.class is: " << (x.class).to_s )
print (s4):["This ", "is", " not a string!", 10]
print (x):["This ", "is", " not a string!", 36]
puts(x):
This
is
not a string!
36
puts x.class is: Array
print(x):["This ", "is", " not a string!", 36]
puts(x):
This
is
not a string!
36
puts x.class is: Array
开发环境:Rubymine
The book of Ruby----A hands-on guide for the Adventurous---[美]Huw Collingbourne---no starch press
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区),文章链接,文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件至:cloudbbs@huaweicloud.com进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。
- 点赞
- 收藏
- 关注作者
评论(0)