现在位置 >首页 > string.find
Lua中实现php的strpos()函数 [原创]已关闭评论
2012年08月24日 Lua ⁄ 被围观 12,252 次+
在来写一个lua中实现php的strpos()函数,查找某个字符串在指定字符串首次出现的位置,其实lua中也为我们提供了这样的函数使用string.find()即可获得,下面我们还是简单写一个函数,代码如下: function strpos (str, f)        if str ~= nil and f ~= nil then            return (string.find(str, f))        else           return nil        end    end   测试如下图所示:
阅读全文