function fromData (s, p)
--字符串s连接字符串p
s = s .. p
--初始化一个空的数值t
local t = {}
--初始化开始位置等于1
local starti = 1
repeat
--从起始位置starti=1开始在字符串s搜索p
local nexti = string.find(s, p, starti)
--把截取的字符串存入到数组里(对s字符串把从字符串第一个位置到第nexti-1的位置进行搜索)
table.insert(t, string.sub(s, starti, nexti-1))
--开始位置按照nexti增加,每次+1
starti = nexti + 1
--比较长度如果位置长度大于字符串s的长度则返回数组t
until starti > string.len(s)
return t
end
一个很实用的LUA函数,在石器里用于读取文本并分割文本中字符串的时候非常好用
版权声明:若无特殊注明,本文皆为《sa60》原创,转载请保留文章出处。
本文链接:一个字符分割的LUA - http://sa60.com/post-285.html
本文标签:石器时代SF石器SFLUA
