Ruby program to illustrate the creation of strings

Ruby Example: Write a program to illustrate the creation of strings.
Submitted by Nidhi, on December 30, 2021

Problem Solution:

In this program, we will illustrate the creation of string. Here, we will print strings enclosed with a single quote, double quotes, and also store string values inside the variables and print them.

Program/Source Code:

The source code to illustrate the creation of strings is given below. The given program is compiled and executed successfully.

# Ruby program to illustrate the 
# creation of strings

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

puts MyStr1;
puts MyStr2;

# Print a string enclosed in 
# single quotes
puts 'Single quote string';

# Print a string enclosed in 
# double quotes
puts "Double quote string";

Output:

Hello India
Single quote string
Double quote string

Explanation:

In the above program, we created two variables MyStr1, MyStr2 to store string values and printed them. Here, we also printed the string enclosed within the single quote and double quote.

Ruby Strings Programs »





Comments and Discussions!

Load comments ↻






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