lua中的大写和小写字符

时间:2018-08-17 15:54:21

标签: lua

    if string.find(reply.result_msg, "deleted") or string.find(reply.result_msg, "Deleted") then
    ---
    end

我可以强迫它更快地工作吗?速度对我很重要。我不想检查两次。

1 个答案:

答案 0 :(得分:3)

您可以这样重写代码:

if string.find(reply.result_msg, "[dD]eleted") then
   ---
end

那行得通,因为

  

[{string.find查找]在字符串s中模式的第一个匹配项(请参见第6.4.1节)。 [...]   
来源:Lua 5.3 Reference Manual

[dD]eleted是一种模式,它允许在第一位置使用大小写字母。

相关问题