返回介绍

string.format (formatstring, ···)

发布于 2019-08-25 13:17:16 字数 1300 浏览 1194 评论 0 收藏 0

Returns a formatted version of its variable number of arguments
following the description given in its first argument (which must be a string).
The format string follows the same rules as the printf family of
standard C functions.
The only differences are that the options/modifiers
*, l, L, n, p,
and h are not supported
and that there is an extra option, q.
The q option formats a string in a form suitable to be safely read
back by the Lua interpreter:
the string is written between double quotes,
and all double quotes, newlines, embedded zeros,
and backslashes in the string
are correctly escaped when written.
For instance, the call

 string.format('%q', 'a string with "quotes" and \n new line')

will produce the string:

 "a string with \"quotes\" and \
 new line"

The options c, d, E, e, f,
g, G, i, o, u, X, and x all
expect a number as argument,
whereas q and s expect a string.

This function does not accept string values
containing embedded zeros.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文