如何在字符串中添加chr(47)'\'?

时间:2019-06-11 12:38:44

标签: string lua

local html_path = "[[" .. GetPostProcessorLocation()
html_path = html_path .. ????  .. "New Please Register Me.html]]"

chr(47)
"\"
exactly what do you need me to type so as to continue?

1 个答案:

答案 0 :(得分:0)

字符47是正斜杠(/),而不是反斜杠(\)。反斜杠是字符92。我假设您的意思是反斜杠,因为正斜杠通常不会引起任何问题。

我也不确定您想使用方括号([[..]])实现什么,因为这实际上是在Lua中表示多行字符串的一种方式,无需其他处理。

以下是Lua 5.2 REPL的有用输出示例:

Lua 5.2.4  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> function GetPostProcessorLocation() return "C:\\Programs"; end
>
> print("[[" .. GetPostProcessorLocation() .. string.char(92)  .. "New Please Register Me.html]]")
[[C:\Programs\New Please Register Me.html]]
> print(GetPostProcessorLocation() .. string.char(92)  .. [[New Please Register Me.html]])
C:\Programs\New Please Register Me.html
> print(GetPostProcessorLocation() .. [[\New Please Register Me.html]])
C:\Programs\New Please Register Me.html
> print(GetPostProcessorLocation() .. [[\\New Please Register Me.html]])
C:\Programs\\New Please Register Me.html
> -- Note the double-backslash in the output above!
> print(GetPostProcessorLocation() .. "\\New Please Register Me.html")
C:\Programs\New Please Register Me.html
> print(string.format("%s\\%s", GetPostProcessorLocation(), "New Please Register Me.html"))
C:\Programs\New Please Register Me.html