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

 汽车时尚宠 发布于 2023-02-12 10:21

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

在Javascript中它看起来像:

'my.string.here.'.lastIndexOf('.')     // returns 14

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"))

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

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有