Cinchoo – String.Unindent(), Extension Method

In this section, I’ll talk about Unindent extension method. This method used to find and remove the padding characters from input text. Please see the below samples on how to use it.

1. Add reference to Cinchoo.Core.ExtensionMethods.dll assembly

2. Namespace System


static void Main(string[] args)
    string msg = "\tHello World!{0}\tWelcome to".FormatString(Environment.NewLine);

    Console.WriteLine("Before Unindent:");

    Console.WriteLine("After Unindent:");

When you run the above code, the output will be

Before Unindent:
        Hello World!
        Welcome to

After Unindent:
Hello World!
Welcome to
Press any key to continue . . .

Unindent() method has several overloads, they are

//Unindent with 1 tab char
//Unindent with 'totalWidth' number of tab chars
Unindent(int totalWidth);
//Unindent with 'totalWidth' number of paddingChars
Unindent(int totalWidth, char paddingChar);

PS: totalWidth should be positive. In case if you pass negative value, this routine will invoke Indent() method to add any leading pad characters from each line of input text.

Happy coding!!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s