C# String.PadLeft Method

CsharpProgrammingServer Side Programming

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
raja
Published on 12-Sep-2018 12:28:47
Advertisements