Indent String with Spaces in C# Example

Updated on April 22, 2016 Kisan Patel

This example shows how to indent strings using method for padding in C#. To repeat spaces use method String.PadLeft. If you call “hello”.PadLeft(5) you will get the string aligned to the right: ” hello”. If you use empty string instead of the “hello” string the result will be 10× repeated space character. This can be used to create simple Indent method.