[英]Lua escape multiline string
Hello I'm wondering if I can escape the [[ and ]] in a mutli line string你好,我想知道我是否可以在多行字符串中转义 [[ 和 ]]
example:例子:
s = [[ [[ test ]] ]]
and then if I do然后如果我这样做
print(test)
I would like the output to be, [[ test ]]
我希望输出是,
[[ test ]]
is there anyway to do this?有没有办法做到这一点?
Lua multiline strings don't just use [[
and ]]
; Lua 多行字符串不仅仅使用
[[
和]]
; you can also put as many =
between the two [
and ]
(it has to be the same number though):您还可以在两个
[
和]
之间放置尽可能多的=
(但必须是相同的数字):
local str = [=====[
]] This does nothing
]=] not enough =
]==========] too many =
]=====] -- This closes the string
s = [=[ [[Hello]] ]=]
print(s)
Output [[Hello]]
输出
[[Hello]]
Seems to work, but I'm just learning this solution as I research to answer this question so I don't know if there are any caveats.似乎有效,但我只是在研究这个问题时学习这个解决方案,所以我不知道是否有任何警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.