判断变量为空
local str = nil
-- local str = false
if str then
-- 不为空的情况
end
if not str then
-- 为空的情况
end
判断字符串非空
方式一:判断长度大于0
local str = ""
if str and #str > 0 then
end
方式二:判断不等于空
local str = ""
if str and str ~= "" then
end
判断变量为空
local str = nil
-- local str = false
if str then
-- 不为空的情况
end
if not str then
-- 为空的情况
end
判断字符串非空
方式一:判断长度大于0
local str = ""
if str and #str > 0 then
end
方式二:判断不等于空
local str = ""
if str and str ~= "" then
end