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. . .
Table of Contents