lua 实现split
来源:互联网 发布:java servlet开发教程 编辑:程序博客网 时间:2024/05/16 23:34
直接上代码:
function Split(s, sp) local res = {} local temp = s local len = 0 while true do len = string.find(temp, sp) if len ~= nil then local result = string.sub(temp, 1, len-1) temp = string.sub(temp, len+1) table.insert(res, result) else table.insert(res, temp) break end end return resend
测试代码:
local s = 'this/is /a test'local t = Split(s, '/')print(#t)for i=1,#t do print(t[i])end
测试结果:
3
this
is
a test
注意:
这里需要注意的是,如果需要分割 . 符号的,sp需要设置为 /. ,否则会出错
0 0
- lua 实现split
- lua实现split的简易方法
- Lua split函数的简易实现
- lua字符串分割 string.split实现
- Lua自己实现string.split功能
- Lua 中自己实现string.Split
- lua split
- lua split
- lua split
- lua split
- Lua split
- Lua语言string对象的split方法实现
- LUA极速字符串分割split函数实现
- Redis 使用 Lua 实现 split 结合 HMGET 批量读取数据
- lua DIY split函数
- lua split函数
- split实现
- Lua 字符串函数扩展 Split
- [SVG笔记] viewBox、enable-background
- HttpRequestWrapper
- shell脚本调用expect命令实现命令行自动交互
- Android系列之网络(二)----HTTP请求头与响应头
- 1003 Java返回值-类、抽象类、接口
- lua 实现split
- oracle 中不常用的单行函数
- 面试官在面试时让我去破解一个软件,我成功了----linux破解
- Servlet购物车源代码
- c++中的类占空间
- R的正态分布函数
- JS常用数字、字符串操作函数总结
- 通过JS模拟select表单,达到美化效果[demo][转]
- Android系列之网络(三)----使用HttpClient发送HTTP请求(分别通过GET和POST方法发送数据)