Ruby program to pad a string with 0's on the right side

Ruby Example: Write a program to pad a string with 0's on the right side.
Submitted by Nidhi, on January 02, 2022

Problem Solution:

In this program, we will create a string and pad the string with 0's on the right side using the ljust() method.

Program/Source Code:

The source code to pad a string with 0's on the right side is given below. The given program is compiled and executed successfully.

# Ruby program to pad a string with 
# 0's on the right side

str = "12345";

lPadStr = str.ljust(10,"0");

print "Left justified string padded with 0's in right side: ",lPadStr;

Output:

Left justified string padded with 0's on right side: 1234500000

Explanation:

In the above program, we created a string str initialized with "12345". Then we used the ljust() method to pad the string from the right side with a specified character and return the updated string. After that, we printed the updated string.

Ruby Strings Programs »





Comments and Discussions!

Load comments ↻






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