Lua string.format options
这似乎是一个愚蠢的问题,但是string.format中用于替换字符串的符号是什么? 有人可以给我指出一个简单的用法示例吗?
Lua中的string.format与c中的Printf遵循相同的模式:
http://www.cplusplus.com/reference/clibrary/cstdio/printf/
有一些例外,请参见此处:
http://pgl.yoyo.org/luai/i/string.format
PiL的第20章在结尾处描述了
The function
string.format is a
powerful tool when formatting strings,
typically for output. It returns a
formatted version of its variable
number of arguments following the
description given by its first
argument, the so-called format string.
The format string has rules similar to
those of theprintf function of
standard C: It is composed of regular
text and directives, which control
where and how each argument must be
placed in the formatted string.
Lua参考说:
The format string follows the same
rules as theprintf family of standard
C functions. The only differences are
that the options/modifiers* ,l ,L ,n ,
p , andh are not supported and that
there is an extra option,q .
该函数由
如果使用安装包,则硬盘中应该有" Lua快速参考" html文件。
(例如:../ Lua / 5.1 / docs / luarefv51.html)
在那里,您会发现,
- 格式指令
- 格式化字段类型
- 格式化标志
- 格式化示例