--------------------------------------------------------------------
-- Create By SunC 2014/7/1
-- Func: 分割字符串
-- szFullString 要分割的字符串
-- szSeparator 分割字符(此处不能为转义字符,否则请先调用gsub("%.", ",")替换后再拆分)
-- nSplitArray 返回分割后的字符串数组
--------------------------------------------------------------------
function Split(self, szFullString, szSeparator)
local nFindStartIndex = 1 ;
local nSplitIndex = 1 ;
local nSplitArray = {} ;
--若是空串,不再分割
if szFullString == nil or szFullString == "" then
return nSplitArray;
end
while true do
local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex) ;
if not nFindLastIndex then
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString)) ;
break
end
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1) ;
nFindStartIndex = nFindLastIndex + string.len(szSeparator) ; nSplitIndex = nSplitIndex + 1 ;
end
return nSplitArray
end