红宝石 |字符串连接方法
concat是 Ruby 中的 String 类方法,用于连接两个 String 对象。如果给定对象是整数,则将其视为代码点并在连接之前转换为字符。
Syntax:String_Object.concat(String_Object)
Parameters: This method can take the string object and normal string as the parameters. If it will take integer then this method will convert them into the character.
Returns: This method returns the concatenated string as a result.
示例 1:
# Ruby program for concat method
# taking a string object
str = "Geeks"
# using the method
str.concat("ForGeeks")
# displaying the result
puts str
输出:
GeeksForGeeks
示例 2:
# Ruby program for concat method
# taking a string object
str = "Geeks"
# using the method
# but taking integer also inside the method
# it will convert it to character
str.concat("ForGeeks", 33)
# displaying the result
puts str
输出:
GeeksForGeeks!