The C# PadRight function is employed to generate a fresh string that aligns the characters to the left within the string by adding spaces to the right side, up to a designated total length.
Signature
Example
public string PadRight(Int32 length)
public string PadRight(Int32, Char)
Parameter
length: it is an integer type parameter.
Return
It returns a string.
C# String PadRight Method Example
Example
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "Hello C#";// 8 length of characters
string s2 = s1.PadRight(15);
Console.Write(s2);//padding at right side (15-8=7)
Console.Write("Hello World");//will be written after 7 white spaces
}
}
Output:
Output
Hello C# C# Tutorial