Ruby/String/String Concatenation

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Содержание

append a string with the

puts "Hello, " << "Matz!"



Append one string to another with the + method:

puts "Hello, " + "Matz!"



Concatenate (join) strings together, using a +

puts "It " + "was " + "too " + "Cary " + "Grant!"



Encode command in string

#!/usr/bin/env ruby
# a nice greeting for myValue
puts "Hey, myValue, I"m running " + "ruby --version"



inserting value of a variable in a string

person = "Matz!"
puts "Hello, #{person}" # => Hello, Matz!



Push several strings into one

"Hello," << " " << "myValue" << "!" # => Hello, myValue!



Using the + symbol concatenates the two strings "

puts "Success!" if "Test" + "String" == "TestString"