function splitLines(str) local delim = "\r?\n" local result,pat,lastPos = {},"(.-)" .. delim .. "()",1 for part, pos in string.gmatch(str, pat) do table.insert(result, part); lastPos = pos end table.insert(result, string.sub(str, lastPos)) return result end
replaced gfind (Lua 5.0) with gmatch (Lua 5.1+)
test run test run with input download show line numbers
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #515 |
Snippet name: | splitLines |
Eternal ID of this version: | #515/1 |
Text MD5: | 92b5aac7e6630ebc0a630fe8fa1ee7ab |
Author: | stefan |
Category: | |
Type: | Lua code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-03-11 15:01:44 |
Source code size: | 297 bytes / 9 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 674 / 165 |
Referenced in: | [show references] |