String Padleft()

The C# PadLeft function is employed to generate a fresh string that aligns the characters to the right when the string's length is shorter than the specified length.

For instance, imagine you have a string "hello C#" with a length of 8 characters, and you apply a padleft of 10. This action moves the string to the right after two spaces. Essentially, the PadLeft function adds padding to the string up to the specified length. This method is commonly employed to format the content of a string.

Signature

Example

public string PadLeft(Int32 length)
public string PadLeft(Int32, Char)

Parameter

length: it is an integer type parameter which is used to pass padding.

Return

It returns string.

C# String PadLeft 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.PadLeft(10);//(10-8=2) adds 2 whitespaces at the left side
        Console.WriteLine(s2);
      }  
    }

Output:

Output

Hello C#

Input Required

This code uses input(). Please provide values below: