对齐输出到文件的文本?列 [英] Aligning Text that is output to file? Columns
问题描述
数据全部正确拉出,但格式不正确。
我有一些数据可以运行,生成一个文本文件。 >
现在,我在每列之间使用了TAB + Variable,但由于不同的变量在字符长度上有所不同,所以显然是不均匀的。这里是布局:
$ p $ 记录名称地址电话方面的东西
...数据在这里。
有什么想法?
String.Format 是您的朋友。
这是非常强大的功能,可以让你调整你的输出。
$ b $例如:
(编辑:删除txt前缀,因为可以现在我想要格式化的数据包含在字符串变量中)
昏暗的结果作为字符串
结果= String.Format({0,-10} {1,-30} {2,-30} {3,-10} {4,20},记录,名称,地址,电话,某物)
结果将在第一个元素(txtRecord)的10个空格列的左侧对齐,依此类推最后一个元素将被格式化为一个有20个空格的列并右对齐如果这还不够,请查看复合格式获得o有用的选项
I have some data which I run through, which generates a textfile.
The data is all pulled correctly, but it doesn't format correctly.
Right now, I am using TAB + Variable to space between each column but it is obviously made uneven as different variables differ in character length. Here is the layout:
RECORD NAME ADDRESS TELEPHONE SOMETHING SOMETHING
... Data is here.
Any ideas?
String.Format is your friend here.
It's very powerfull and gives you the function to align your output.
For example: (EDIT: removed the txt prefix because could be confusing, now I suppose that data to be formatted is contained in string vars)
Dim result as string
result = String.Format("{0,-10}{1,-30}{2,-30}{3,-10}{4,20}", Record, Name, Address, Telephone, Something)
The result will be aligned to the left in a 10 space column for the first element (txtRecord) and so on for the remainders, the last element will be formatted in a column with 20 space and right aligned
If that's not enough look at composite formatting to get other useful options
这篇关于对齐输出到文件的文本?列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!