Sxw1212

Chunking Strings

Sep 29th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. function chunk(str,parts)
  2. local len=math.floor(#str/parts)
  3. local res={}
  4. for i=0,parts-1 do
  5. table.insert(res,string.sub(str,len*i,(len*(i+1))-1))
  6. end
  7. if len*parts~=#str then
  8. res[#res]=string.sub(str,(len*(parts-1)))
  9. end
  10. return res
  11. end
Advertisement
Add Comment
Please, Sign In to add comment