Created
September 11, 2014 14:55
-
-
Save cl4u2/518c96b7e34af458ded6 to your computer and use it in GitHub Desktop.
Delete first n lines of a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function del_first_lines(astring, n) | |
-- parameters: string and number of initial lines to be deleted | |
local result = "" | |
local deleted = n | |
local newfirst = true | |
for line in astring:gmatch("[^\r\n]+") do | |
if deleted > 0 then | |
deleted = deleted - 1 | |
else | |
if newfirst then | |
result = result .. line | |
newfirst = false | |
else | |
result = result .. "\n" .. line | |
end | |
end | |
end | |
return result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment