【问题标题】:Using a variable as a prefix argument to a format directive使用变量作为格式指令的前缀参数
【发布时间】:2013-11-22 10:02:36
【问题描述】:

我需要在它之前打印一些带有可变数量空格的东西。例如,如果我需要在文本前打印 5 个空格,我会这样做:

(format T "%5T My Text")
Output:     My Text

我可以使用变量来代替 5 并能够将值传递给它吗?我正在寻找的是这样的:

(format T "%(~d)T My Text" 5)
output:     My Text

【问题讨论】:

    标签: format common-lisp


    【解决方案1】:

    试试

    (format T "~vT My Text" 5)
    

    22.3 Formatted Output:

    可以使用V(或v)代替指令的前缀参数。 在这种情况下,format 将来自 args 的参数作为参数传递给 指示。参数应该是一个整数字符。如果 arg V 参数使用的是nil,效果就好像参数有 被省略了。 # 可以用来代替前缀参数;它 表示剩余要处理的 args 个数。使用时 在递归格式中,在~?~{ 的上下文中,# 前缀 参数表示剩余的格式参数的数量 递归调用。

    【讨论】:

      猜你喜欢
      • 2011-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多