Skip to content

Instantly share code, notes, and snippets.

@nefftd
Created March 12, 2015 23:58
Show Gist options
  • Save nefftd/e7209526130609e98f08 to your computer and use it in GitHub Desktop.
Save nefftd/e7209526130609e98f08 to your computer and use it in GitHub Desktop.
function characters_to_array(str, length)
-- Returns an array where every (length) character are split into a new field
-- of said array.
if #str == 0 then return {} end
local a,i = {},1
repeat
a[i] = str:sub(1,length)
i = i + 1
str = str:sub(length+1)
until str == ''
return a
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment