In this program, we will demonstrate the different ways of string concatenation and print the string after concatenation.
Program/Source Code:
The source code to demonstrate the string concatenation is given below. The given program is compiled and executed successfully.
# Ruby program to demonstrate the # string concatenation. # Concatenate using "+" operator. MyStr1 = "Hello " + "World"; puts MyStr1; # Concatenate using a single space. MyStr2 = "Hello " "World"; puts MyStr2; # Concatenate using "<<" operator. MyStr3 = "Hello " << "World"; puts MyStr3; # Concatenate using concat() method. MyStr4 = "Hello ".concat("World"); puts MyStr4;
Output:
Hello World Hello World Hello World Hello World
Explanation:
In the above program, we created string variables and assigned values by concatenating strings using different ways and printed the result.
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Program/Source Code:
The source code to demonstrate the string concatenation is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created string variables and assigned values by concatenating strings using different ways and printed the result.
need an explanation for this answer? contact us directly to get an explanation for this answer