我只是一个普遍的问题.
在Lua中使用单引号和双引号有什么不同吗?
例:
require('test.lua') require("test.lua")
当我在PAWN中编程一种类似于C的语言时,单引号可以用于字符,但不能用于文本字符串,您必须为它们使用双引号.
如果没有区别,哪一个建议使用?
这个问题很可能已经被回答了,但是我没有找到已经回答的话题.
谢谢.
解决方法@H_404_18@
不.没有区别,除了你可以将其他内容包围在你正在使用的.
-- No difference between these
myStr = "Hi!!"
myStr = 'Hi!!'
myStr = [[Hi!!]] -- The 'weird' way to make a string literal IMO...
-- Double quotes enclosed in single quotes
myStr = 'My friend said: "Hi!!"'
-- Single quotes enclosed in double quotes
myStr = "My friend said: 'Hi!!'"
-- Single and double quotes enclosed in double brackets
myStr = [[My friend said: "What's up?"]]
请参阅:Strings in Lua了解更多信息.
-- No difference between these myStr = "Hi!!" myStr = 'Hi!!' myStr = [[Hi!!]] -- The 'weird' way to make a string literal IMO... -- Double quotes enclosed in single quotes myStr = 'My friend said: "Hi!!"' -- Single quotes enclosed in double quotes myStr = "My friend said: 'Hi!!'" -- Single and double quotes enclosed in double brackets myStr = [[My friend said: "What's up?"]]
请参阅:Strings in Lua了解更多信息.