Lua敏感词过滤

我对Lua的水平一般般,但我正在玩这个

local profanitywords = {"fuck", "shit", "ass"} -- 一个小列表
local input = io.read()

for i,v in ipairs (profanitywords) do
   if string.find(input:lower(), v) then
      print("敏感词")
   else
       print("非敏感词")
   end
end

但是我得到的输出结果是这样的:

输出图片 另外,我使用的是zerobrane studios

有时候当我输入其他内容时,它根本不起作用。请帮助?

点赞
用户6834680
用户6834680
local profanity
-- 针对保留字列表循环判断输入字符串是否包含敏感词汇并设置 profanity 变量
for i,v in ipairs(profanitywords) do
   if string.find(input:lower(), v) then
      profanity = true
      break
   end
end

-- 根据 profanity 变量输出相应结果
if profanity then
    print("Profanity")
else
    print("Not Profanity")
end
2016-12-16 12:50:53