In this section, I’ll talk about Indent extension method. This method used to indent a string with the padding characters. Please see the below samples on how to use it.
1. Add reference to Cinchoo.Core.ExtensionMethods.dll assembly
2. Namespace System
Sample:
static void Main(string[] args) { string msg = "Hello World!{0}Welcome to Cinchoo.com".FormatString(Environment.NewLine); Console.WriteLine("Before Indent:"); Console.WriteLine(msg); Console.WriteLine(); Console.WriteLine("After Indent:"); Console.WriteLine(msg.Indent()); }
When you run the above code, the output will be
Before Indent: Hello World! Welcome to Cinchoo.com After Indent: Hello World! Welcome to Cinchoo.com Press any key to continue . . .
Indent() method has several overloads, they are
//Indent with 1 tab char Indent(); //Indent with 'totalWidth' number of tab chars Indent(int totalWidth); //Indent with 'totalWidth' number of paddingChars Indent(int totalWidth, char paddingChar);
PS: totalWidth should be positive. In case if you pass negative value, this routine will invoke Unindent() method to remove any leading pad characters from each line of input text.
Happy coding!!!
