How to use string format to add with padding in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            const string format = "{0, -13} {1, 13}";

            string s1 = string.Format(format, 982, 16);
            string s2 = string.Format(format, "csharp", "python");

            Console.WriteLine(s1);
            Console.WriteLine(s2);
        }
    }
}


/*
run:
   
982                      16
csharp               python
 
*/

 



answered Aug 20, 2018 by avibootz

Related questions

1 answer 182 views
2 answers 75 views
1 answer 214 views
3 answers 250 views
1 answer 162 views
1 answer 88 views
...