红宝石 |字符串 + 方法
+()是 Ruby 中的 String 类方法,用于返回一个新字符串,该字符串包含与给定字符串。
Syntax: str + other_str
Parameters: Here, str and other_str are the strings which are to be concatenated.
Returns: Returns the concatenated string.
示例 1:
#ruby 2.3.1
# Ruby program to demonstrate
# the + method
# Taking a string and
# using the method
puts "Hello " + "Geeks!"
puts "Ruby " + "String"
输出:
Hello Geeks!
Ruby String
示例 2:
#ruby 2.3.1
# Ruby program to demonstrate
# the + method
# Taking a string and
# using the method
puts "Hey " + "Champ"
puts "Kirti " + "Mangal"
输出:
Hey Champ
Kirti Mangal