C# String.PadLeft Method


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

Let’s say the following is our string.

string myStr = "DemoOne";

To set a padding at the beginning of the above string, use the PadLeft method.

myStr.PadLeft(10);

Here is the complete example.

Example

 Live Demo

using System;
class Demo {
   static void Main() {
      string myStr = "DemoOne";
      // set padding at the beginning
      Console.WriteLine(myStr.PadLeft(10));
      myStr = "DemoTWO";
      // set padding at the beginning
      Console.Write(myStr.PadLeft(15));
   }
}

Output

DemoOne
DemoTWO

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 23-Jun-2020

262 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements