lua判断子串,字符串替换,字符串分割

故事背景,需要在聊天做一个gm命名,如果输入的字符串带有'@',则根据后面的参数调用函数。匹配函数的时候需要去掉"@"。字符串还需要切割成函数名和参数。

Lua 复制代码
function string.split(input, delimiter)
    input = tostring(input)
    delimiter = tostring(delimiter)
    if (delimiter=='') then return false end
    local pos,arr = 0, {}
    -- for each divider found
    for st,sp in function() return string.find(input, delimiter, pos, true) end do
        table.insert(arr, string.sub(input, pos, st - 1))
        pos = sp + 1
    end
    table.insert(arr, string.sub(input, pos))
    return arr
end


local content = "@additem 1 1"
if content:find("@") then
	print("gm")
end
local content = string.gsub(content, "@", '')
print(content)


local t = string.split(content," ")
for k,v in pairs(t)do
	print(v)
end
相关推荐
LcGero7 小时前
游戏引擎Luanti的前世今生与技术解析
游戏引擎·lua·游戏开发·我的世界·luanti
绿草在线1 天前
SpringBoot请求与响应全解析
spring boot·后端·lua
心之所向,自强不息2 天前
VSCode + EmmyLua 调试 Unity Lua(最简接入 + 不阻塞运行版)
vscode·unity·lua
weixin_408099672 天前
Lua请求文字识别ocr api
图像处理·人工智能·后端·ocr·lua·api·文字识别
上海合宙LuatOS3 天前
LuatOS扩展库API——【libfota】远程升级
物联网·junit·lua·luatos
拾贰_C5 天前
【Google | Gemini | API | POST】怎么使用Google 的Gemini API (原生版)
开发语言·lua
12亡灵归来345 天前
Postman高级用法:自动化测试与Mock
测试工具·lua·postman
chxii5 天前
lua 下载和配置环境变量
开发语言·lua
上海合宙LuatOS6 天前
LuatOS扩展库API——【httpplus】HTTP客户端
网络·物联网·网络协议·http·lua·luatos
上海合宙LuatOS6 天前
LuatOS扩展库API——【 lbsLoc2】免费版单基站定位
数据库·物联网·oracle·junit·lua·luatos