查找字符串中字符的最后一个索引

Kos*_*ika 9 string lua

我希望能够lastIndexOf在Lua(Luvit)项目中为字符串使用方法.不幸的是,没有内置的这种方法,我现在有点卡住了.

在Javascript中它看起来像:

'my.string.here.'.lastIndexOf('.')     // returns 14
Run Code Online (Sandbox Code Playgroud)

lhf*_*lhf 10

function findLast(haystack, needle)
    local i=haystack:match(".*"..needle.."()")
    if i==nil then return nil else return i-1 end
end
s='my.string.here.'
print(findLast(s,"%."))
print(findLast(s,"e"))
Run Code Online (Sandbox Code Playgroud)

请注意,要找到.你需要逃避它.