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

Sample:

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

    Console.WriteLine("Before Unindent:");
    Console.WriteLine(msg);
    Console.WriteLine();

    Console.WriteLine("After Unindent:");
    Console.WriteLine(msg.Unindent());
}

When you run the above code, the output will be

Before Unindent:
        Hello World!
        Welcome to Cinchoo.com

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

Unindent() method has several overloads, they are

//Unindent with 1 tab char
Unindent();
//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!!!

About these ads

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s