1 | function splitLines(str) |
2 | local delim = "\r?\n" |
3 | local result,pat,lastPos = {},"(.-)" .. delim .. "()",1
|
4 | for part, pos in string.gmatch(str, pat) do |
5 | table.insert(result, part); lastPos = pos |
6 | end |
7 | table.insert(result, string.sub(str, lastPos)) |
8 | return result |
9 | 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: | 946 / 222 |
| Referenced in: | [show references] |