gpt4 book ai didi

format - 使用变量作为格式指令的前缀参数

转载 作者:行者123 更新时间:2023-12-04 17:22:18 25 4
gpt4 key购买 nike

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

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

代替 5,我可以使用变量并能够将值传递给它吗?我正在寻找的是这样的:
(format T "%(~d)T My Text" 5)
output: My Text

最佳答案

尝试

(format T "~vT My Text" 5)

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.

关于format - 使用变量作为格式指令的前缀参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19892186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com