C# Program to Perform the Right Padding Without Using the Padright() Method

You are currently viewing C# Program to Perform the Right Padding Without Using the Padright() Method

C# program to perform the right padding without using the PadRight() method

//C# program to perform right padding 
//without using PadRight() method. 

using System;

class Demo
{
    static string StrPadRight(string str, char ch, int num)
    {
        string result = "";

        result += str;
        for (int i = 0; i < num; i++)
        {
            result += ch;
        }

        return result;
    }
    static void Main(string[] args)
    {
        string Str      =   "";
        string paddedStr=   "";

        Console.Write("Enter a string: ");
        Str = Console.ReadLine();

        paddedStr=StrPadRight(Str, '$', 5);
        Console.WriteLine("Padded String: " + paddedStr);
    }
}

Output

Enter a string: Codingdiksha
Padded String: Codingdiksha$$$$$
Press any key to continue. . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply