中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟
中国DOS联盟论坛
现在时间是 2026-08-15 19:53
47,813 主题排行 / 349,903 发帖 / 今日 1 篇 / 48,258 会员排行
DOS疑难解答 & 问题讨论 (解答室) » [求助]dos7.1下,用echo将字符输出到文件,能否进行对齐
可打印版本  1,326 / 5
第1楼 nobodytt 发表于 2009-02-01 19:58
初级用户 发帖 33 积分 78
[求助]dos7.1下,用echo将字符输出到文件,能否进行对齐
比如用echo向文件中输入两行两列文字,则如果第一列的文字不一样长,那么第二列以后的文字就不能保持对齐,如下所示:

123456 test
123 test


不知在dos7.1下有没有办法对echo输出到文件的内容进行对齐?
第2楼 Sufone 发表于 2009-02-02 12:31
中级用户 发帖 124 积分 256
echo命令只是将文本不加任何修改的显示,不借助其他命令无法实现楼主的要求
第3楼 nobodytt 发表于 2009-02-02 15:37
初级用户 发帖 33 积分 78
那么有没有什么好的外部命令可以实现?
第4楼 DOSforever 发表于 2009-02-06 00:51
金牌会员 发帖 2,239 积分 4,639
你想怎么个对齐,左对齐?右对齐?每列首对齐?
第5楼 nobodytt 发表于 2009-02-06 17:06
初级用户 发帖 33 积分 78
每列左对齐
第6楼 DOSforever 发表于 2009-02-06 17:52
金牌会员 发帖 2,239 积分 4,639
可以用 4DOS 的 @format 变量函数

4DOS Help Topic: @FORMAT


@FORMATx],string]: Reformats a string, truncating it or padding
it with spaces as necessary. If you use the minus , the string is
left-justified; otherwise, it is right-justified. The x value is the
minimum number of characters in the result. The y value is the maximum
number of characters in the result. You can combine the options as
necessary. For example:

"%@format" returns " JPSoftware"
"%@format" returns "JPS"

@FORMAT will add leading or trailing spaces if necessary to pad the result
to the minimum width specified by x. If a leading zero is used before x,
the padding will be with 0's instead, for example:

"%@format" returns " 5"
"%@format" returns "0005"
"%@format" returns "5000"

See also the @COMMA function, which can make numeric values easier to read
by inserting thousands separators.


要每列左对齐的话,也就是说前一列的长度都要相同,少于所需长度的要填充空格(也可以是0),以你的例子为例,假定第一列的最大字串长度为6(列之间的空格不计,是随便你预先输入的,当然,也可以包括到函数中去)。

echo %@format test

得到的结果就是

123 test
[ 联系联盟系统管理团队 - 中国DOS联盟 - 标准版 ]
Sponsored by ifanr Inc | © 2001–2023