Lua忽略转义序列

编程入门 行业动态 更新时间:2024-10-13 16:17:28
本文介绍了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忽略转义序列

本文发布于:2023-10-08 15:04:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472977.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列   Lua

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!