How to do Alignment within string.Format c#?

前端 未结 1 1736
野的像风
野的像风 2020-12-03 10:12

Hi I have a problem I have this line of code:

return string.Format(\"{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}\", Name, CPSA, PostCode, Ra         


        
相关标签:
1条回答
  • 2020-12-03 10:23

    You can do something like this:

    Console.WriteLine(String.Format("{0,-10} | {1,5}", "Bill", 51));
    

    You'll get "51" aligned to right on 5 characters.

    More examples here: Align String with Spaces.

    For official reference, look Composite Formatting

    0 讨论(0)
提交回复
热议问题