Lua 中带有单反斜杠 (!) 的字符串需要转义或替换 - 如何操作?
Adobe Lightroom 中的插件是用 Lua 编写的。为了自学 Lua,我正在通过 SDK 制作自己的插件。 现在我遇到了一种情况,我从名为“images”的表中获取一个字符串,如下所示:
images[1] = "d:\Windows\Temp\LREXPORT\NK119542.tif"
但是Lua当然不喜欢那些未转义的反斜杠。该表的内容根据用户操作而变化。我正在考虑一种解决方案来获取该字符串并对其进行操作以进行进一步处理。
正确的字符串是:
newimages = "d:/Windows/Temp/LREXPORT/NK119542.tif"
newimages = "d:\\Windows\\Temp\\LREXPORT\\NK119542.tif"
浏览了大量帖子和在线教程,但抱歉,我无法弄清楚这一点。 希望有解决办法,谢谢回复。
In Adobe Lightroom a Plug-in is written in Lua. In an attempt to teach myself Lua I am working myself through the SDK producing own Plug-ins.
Now I came accross a situation where I am getting a string from a table named 'images' like this:
images[1] = "d:\Windows\Temp\LREXPORT\NK119542.tif"
But of course Lua does not like those unescaped backslashes at all. The content of this table varies depending on the user action. I am thinking of a solution to grab that string and manipulate it for further processing.
Correct strings would be:
newimages = "d:/Windows/Temp/LREXPORT/NK119542.tif"
newimages = "d:\\Windows\\Temp\\LREXPORT\\NK119542.tif"
Went through lots of posts and online tutorials but sorry, I was not able to figure this one out.
Hope there is a solution, thanks for replies.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
[[
和]]
分隔字符串:You can delimit your string with
[[
and]]
:如果您可以使用正斜杠,为什么不直接替换它们:
如果您认为将它们加倍会对您有帮助,那么同样如此:
if your fine with forward slashes, why not just replace them:
Same goes if you think doubling them will help you:
我遇到了同样的问题,对我来说这有效:
所以
images[i]=images[i]:gsub("\\\\","/")
也应该有效。I had the same problem, and for me this worked:
so
images[i]=images[i]:gsub("\\\\","/")
should work as well.