在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
-------------------------------------------------------------------- -- 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 |
请发表评论