Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

9
LINES

< > BotCompany Repo | #515 // splitLines

Lua code

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

Author comment

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: 675 / 166
Referenced in: #513 - Snippet merger (side by side)
#516 - splitLines test
#517 - mergeTexts (side by side merger, include)
#518 - Automated annotations (testing)
#519 - Automated annotations (v2 / testing)
#520 - Backport keywords from new case to known case
#523 - Print compacted table header for snippet type identification purposes
#524 - Find snippet references in a text
#531 - Process questionnaire
#534 - Parse questionnaire
#554 - Stefan's phone detect
#555 - Stefan's tablet detect
#2000292 - Process questionnaire
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)