现在的位置: 首页Lua>正文
Lua中实现php的strpos()函数 [原创]
2012年08月24日 Lua Lua中实现php的strpos()函数 [原创]已关闭评论 ⁄ 被围观 12,253 次+

在来写一个lua中实现phpstrpos()函数,查找某个字符串在指定字符串首次出现的位置,其实lua中也为我们提供了这样的函数使用string.find()即可获得,下面我们还是简单写一个函数,代码如下:

  1. function strpos (str, f)   
  2.     if str ~= nil and f ~= nil then   
  3.         return (string.find(str, f))   
  4.     else  
  5.         return nil   
  6.     end   
  7. end  

测试如下图所示:

本文地址:http://www.92csz.com/37/1187.html
如非注明则为本站原创文章,欢迎转载。转载请注明转载自:moon's blog
 

抱歉!评论已关闭.