RosettaCodeData/Task/Empty-string/Lua/empty-string.lua

26 lines
537 B
Lua
Raw Permalink Normal View History

2019-09-12 10:33:56 -07:00
-- create an empty string 3 different ways
str = ""
str = ''
str = [[]]
2013-04-10 16:57:12 -07:00
-- test for empty string
if str == "" then
print "The string is empty"
end
-- test for nonempty string
if str ~= "" then
print "The string is not empty"
end
2019-09-12 10:33:56 -07:00
-- several different ways to check the string's length
if string.len(str) == 0 then
print "The library function says the string is empty."
end
if str:len() == 0 then
print "The method call says the string is empty."
end
if #str == 0 then
print "The unary operator says the string is empty."
end