• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >Lua > Lua中实现php的strpos()以及strrpos()函数

Lua中实现php的strpos()以及strrpos()函数

作者:hebedich 字体:[增加 减小] 来源:互联网

hebedich 通过本文主要向大家介绍了php strpos,php strpos函数,php中strpos,php mb strpos,strpos php php等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

在来写一个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 
</div>

测试如下图所示:

下面在来个strrpos()函数,查找某个字符串在指定字符串最后一次出现的位置,下面我们还是简单写一下函数,代码如下:

function strrpos (str, f)  
    if str ~= nil and f ~= nil then  
        local t = true 
        local offset = 1 
        local result = nil  
        while (t)  
        do 
            local tmp = string.find(str, f, offset)  
            if tmp ~= nil then  
                offset = offset + 1 
                result = tmp  
            else 
                t = false 
            end  
        end  
        return result  
    else 
        return nil  
    end  
end 
</div>

测试如下图(注意:如果要查找 . 需要进行转义,使用"%."):

好了,今天就先到这里,以后我们继续实现其他函数功能

</div>

您可能想查找下面的文章:

  • Lua中实现php的strpos()以及strrpos()函数

相关文章

  • Lua性能优化技巧(五):削减、重用和回收
  • Lua中的常用函数库汇总
  • Lua中调用C语言函数实例
  • Lua中字符串(string)浅析
  • Lua教程(十四):字符串库详解
  • Lua模拟面向对象示例分享
  • Lua中__index和__newindex之间的沉默与合作
  • Lua在各个操作系统中的开发环境配置教程
  • Lua面向对象编程之类的简单实现方式
  • Lua和C语言的交互详解

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Lua性能优化技巧(一):前言
    • Lua loadstring函数用法实例
    • Lua中调用C语言函数实例
    • 使用Lua编写Nginx服务器的认证模块的方法
    • 详解Lua中的数据类型
    • Lua中的函数相关知识点整理汇总
    • LUA string库使用小结
    • Lua脚本语言简明入门教程
    • lua闭包的理解以及表与函数的几种表达方法
    • Lua中string.len()使用指南

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有