Ruby program to illustrate the difference between single quote string and double-quote string

Ruby Example: Write a program to illustrate the difference between single quote string and double-quote string.
Submitted by Nidhi, on December 30, 2021

Problem Solution:

In this program, we will illustrate the difference between a single quote string and a double-quoted string. The single quote string cannot interpolate the variables.

Program/Source Code:

The source code to illustrate the difference between single quote string and double-quote string is given below. The given program is compiled and executed successfully.

# Ruby program to illustrate the difference between 
# single quote string and double-quote string.

# Create variables to store 
# string values.
MyStr1 = "Hello World";
MyStr2 = "Hello India";

puts 'Single quote string: #{Mystr1}';
puts "Double quote string: #{MyStr2}";

Output:

Single quote string: #{Mystr1}
Double quote string: Hello India

Explanation:

In the above program, we created two variables MyStr1, MyStr2 to store string values. Then we used single quote and double quote strings to interpolate string variables and found that we cannot interpolate string variables inside the single quote string.

Ruby Strings Programs »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.