Lua String 的扩展函数
2016-02-23 18:07
435 查看
字符串分割函数返回 Table
string.split = function(line, sep)
sep = sep or ' '
local retval = {}
local pos = 1
while true do
local from, to = string.find(line, sep, pos)
if from then
local item = string.sub(line, pos, from-1)
table.insert( retval, item )
pos = to + 1
else
local item = string.sub(line, pos)
table.insert( retval, item )
break
end
end
return retval
end
string.split = function(line, sep)
sep = sep or ' '
local retval = {}
local pos = 1
while true do
local from, to = string.find(line, sep, pos)
if from then
local item = string.sub(line, pos, from-1)
table.insert( retval, item )
pos = to + 1
else
local item = string.sub(line, pos)
table.insert( retval, item )
break
end
end
return retval
end
相关文章推荐
- Lua debug library
- LuaInterface简介
- 利用Excel中VBA的Evaluate方法对字符串进行解析计算
- lua 远程调试 【zeroBrane 使用mobdebug】
- Lua程序设计 第17章 弱引用笔记
- quick3.3使用tolua工具导出C++到lua所遇问题记录
- Lua学习Day02
- Lua中分割字符串
- 150. Evaluate Reverse Polish Notation
- uLua中遇到的问题
- Lua基础之字符串(string)
- Lua基础之语法
- Lua中cJson的读写
- Lua基础之Function
- 使用tolua++编译pkg,从而创建自定义类让Lua脚本使用
- Lua基础之table详解
- Lua基础之coroutine(协程)
- 快速掌握Lua 5.3 —— 字符串库 (3)
- Lua 编程: 如何给文件写入二进制数据
- lua基础知识笔记