函数:string.find 查找字符串

函数名称:查找字符串

函数功能:根据匹配项查找数据

函数方法

num1,num2 = string.find(s,pattern,in,plain)

参数 类型 必填 说明
s string 原字符串
pattern string 待查找的字符串或模式匹配
in number 从第几个字符开始搜索,不写默认为 1
pllain boolean 是否搜索纯文本,否即支持模式匹配搜索,不写默认为 false
返回值 类型 说明
num1 number/nil pattern 位于 s 的起点位置,nil 为没找到
num2 number/nil pattern 位于 s 的终点位置,nil 为没找到

模式匹配用法

参数 说明
. 任意字符
%s 空白符
%p 标点字符
%c 控制字符
%d 数字
%x 十六进制数字
%z 代表 0 的字符
%a 字母
%l 小写字母
%u 大写字母
%w 字母和数字

函数用例

num1,num2 = string.find("bbaaadd","aaa")
if num1~= nil and num2~= nil then
dialog("开始位置:"..num1.."\r\n".."结束位置:"..num2,5)
else
    dialog("未找到")
end
Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""