Padding character with string


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Padding
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "This is a text";
            char padChar = '.';

            Console.WriteLine(str.PadLeft(25, padChar));
            Console.WriteLine(str.PadLeft(2, padChar));

            Console.WriteLine(str.PadRight(25, padChar));
            Console.WriteLine(str.PadRight(2, padChar));

            str = "I am Mahedee hasan. Software Architect, Leadsoft Bangladesh Ltd";
            Console.WriteLine((str.PadRight(25, padChar)));

            Console.WriteLine((str.PadRight(25,padChar)).Substring(0,24)+"...");

            Console.ReadKey();
        }
    }
}


/* Output:

...........This is a text
This is a text
This is a text...........
This is a text
I am Mahedee hasan. Software Architect, Leadsoft Bangladesh Ltd
I am Mahedee hasan. Soft...

*/



Please share, if it is helpfulShare on FacebookShare on LinkedInTweet about this on TwitterShare on Google+Email this to someonePrint this page

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>