我如何将“\”放在字符串中而不取消前面的撇号?
How would I put “\” in a string without the apostrophe in the front of it being cancelled out?
例如,如果我这样做:
print(“\”)
它会说:`未完成的字符串附近:'“”'
而不是我预期的输出:'\'
我该如何打印?我在 google 上搜索过,但仍未找到答案。
反斜杠(\
)是escaping后面的字符,是双引号("
),导致字符串未完成。
要在您的字符串中包含一个实际的反斜杠,您可以使用另一个反斜杠将其转义:
print("\")
来自 Lua 5.4 Reference Manual,§3.1(强调我的):
A short literal string can be delimited by matching single or double quotes, and can contain the following C-like escape sequences: '\a' (bell), '\b' (backspace), '\f' (form feed), '\n' (newline), '\r' (carriage return), '\t' (horizontal tab), '\v' (vertical tab), '\' (backslash), '"' (quotation mark [double quote]), and ''' (apostrophe [single quote]). [...]
例如,如果我这样做:
print(“\”)
它会说:`未完成的字符串附近:'“”' 而不是我预期的输出:'\'
我该如何打印?我在 google 上搜索过,但仍未找到答案。
反斜杠(\
)是escaping后面的字符,是双引号("
),导致字符串未完成。
要在您的字符串中包含一个实际的反斜杠,您可以使用另一个反斜杠将其转义:
print("\")
来自 Lua 5.4 Reference Manual,§3.1(强调我的):
A short literal string can be delimited by matching single or double quotes, and can contain the following C-like escape sequences: '\a' (bell), '\b' (backspace), '\f' (form feed), '\n' (newline), '\r' (carriage return), '\t' (horizontal tab), '\v' (vertical tab), '\' (backslash), '"' (quotation mark [double quote]), and ''' (apostrophe [single quote]). [...]