ADVERTISEMENT
ADVERTISEMENT

Ruby program to demonstrate the string concatenation

Ruby Example: Write a program to demonstrate the string concatenation.
Submitted by Nidhi, on December 31, 2021

Problem Solution:

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.

Ruby Strings Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.