Using a variable as a prefix argument to a format directive

后端 未结 1 1506
温柔的废话
温柔的废话 2021-01-19 02:51

I need to print something with variable number of spaces before it. For example if I need to print 5 spaces before my text, I will do:

(format T \"%5T My Tex         


        
1条回答
  •  醉话见心
    2021-01-19 03:37

    Try

    (format T "~vT My Text" 5)
    

    See 22.3 Formatted Output:

    In place of a prefix parameter to a directive, V (or v) can be used. In this case, format takes an argument from args as a parameter to the directive. The argument should be an integer or character. If the arg used by a V parameter is nil, the effect is as if the parameter had been omitted. # can be used in place of a prefix parameter; it represents the number of args remaining to be processed. When used within a recursive format, in the context of ~? or ~{, the # prefix parameter represents the number of format arguments remaining within the recursive call.

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