C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C# String PadLeft()The C# PadLeft() method is used to get a new string that right-aligns the characters in this string if the string length is less than the specified length. For example, suppose you have "hello C#" as the string which has 8 length of characters and you are passing 10 for the padleft, it shifts the string at right side after two whitespaces. It means PadLeft() method provides padding to the string for the specified length. It is used for formatting string content. Signaturepublic string PadLeft(Int32 length) public string PadLeft(Int32, Char) Parameterlength: it is an integer type parameter which is used to pass padding. ReturnIt returns string. C# String PadLeft() Method Exampleusing 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: Hello C#
Next TopicC# String PadRight()
|