本文介绍了Lua忽略转义序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当前Lua具有以下转义序列:
Currently Lua has the following Escape Sequences:
- \a :贝尔
- \b :退格
- \f :表单供稿
- \n :换行符
- \r :回车
- \t :制表符
- \v :垂直标签
- \\ :反斜杠
- \ :双引号
- \':单引号
- \nnn :八进制值(nnn是3个八进制数字)
- \xNN :十六进制值(Lua5.2 / LuaJIT,NN是两个十六进制数字)
- \a: Bell
- \b: Backspace
- \f: Form feed
- \n: Newline
- \r: Carriage return
- \t: Tab
- \v: Vertical tab
- \\: Backslash
- \": Double quote
- \': Single quote
- \nnn: Octal value (nnn is 3 octal digits)
- \xNN: Hex value (Lua5.2/LuaJIT, NN is two hex digits)
如何使用诸如 \a\f\\\这样的字符串忽略所有这些转义序列,直译为可以这么说吗?
How could I use a string such as "\a\f\\\"" ignoring all these escape sequences, interpreting it literally so to speak?
推荐答案我相信您可以做到 [[\a\f\\]]
在转义序列下查看此处: lua-users/wiki/StringsTutorial
Look here under Escape Sequences: lua-users/wiki/StringsTutorial
您也许还可以做一些 string.format 和%q ,但我不记得这会如何产生。我认为它以适合有效Lua的格式显示字符串。
You might also be able to do something with string.format and %q, but I don't remember how that will result off the top of my head. I think it presents the string in a format suitable to be valid Lua.
更多推荐
Lua忽略转义序列
发布评论