怎么办内的String.Format C#对齐? [英] How to do Alignment within string.Format c#?

查看:518
本文介绍了怎么办内的String.Format C#对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个问题,我此行的code:

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, Rank, Score1, Score2, Score3, Score4, Score5, Score6, Score7, Score8);

这从一个文本文件,在吸引它的数据,并在列表框中输出。 我想在梦幻世界证明它的一半向左一半向右所以这样的:

It draws it data from a text file and is output in a list box. I want to justify half of it to the left and half to the right so in dream world this:

return string.Format("align=left({0}, {1}, {2}, {3}, {4},) align=right ({5}, {6}, {7}, {8}, {9}, {10}, {11})", Name, CPSA, PostCode, Rank, Score1, Score2, Score3, Score4, Score5, Score6, Score7, Score8);

我环顾四周,但不知道如何做到这一点,我也是有点codeING小白,所以请解释。 code是C#谢谢

I have looked around but have no clue how to do it, i am also a bit of a codeing noob so please explain. code is C# Thanks

推荐答案

您可以做这样的事情:

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

您会得到51靠右侧的5个字符。

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

更多的例子在这里:对齐字符串空间

有关负责人参考,看看复合格式

For official reference, look Composite Formatting

这篇关于怎么办内的String.Format C#对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆