C# String.PadRight Method


Pad the end of the string with spaces using the PadRight() method. You can also pad it with a Unicode character.

Let’s say the following is our string.

string myStr = "Text1";

To set a padding at the end of the above string, use the PadRight method.

myStr.PadRight(10);

Here is the complete example.

Example

 Live Demo

using System;
class Demo {
   static void Main() {
      string myStr = "Text1";
      // set padding at the end
      Console.Write(myStr.PadRight(10));
      Console.WriteLine("Text2");
   }
}

Output

Text1 Text2

Updated on: 23-Jun-2020

219 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements