string split in lua


/ Published in: Lua
Save to your folder(s)

Example of: split, for, string concatenation, function call, etc


Copy this code and paste it in your HTML
  1. function split (s,t)
  2. local l = {n=0}
  3. local f = function (s)
  4. l.n = l.n + 1
  5. l[l.n] = s
  6. end
  7. local p = "%s*(.-)%s*"..t.."%s*"
  8. s = string.gsub(s,"^%s+","")
  9. s = string.gsub(s,"%s+$","")
  10. s = string.gsub(s,p,f)
  11. l.n = l.n + 1
  12. l[l.n] = string.gsub(s,"(%s%s*)$","")
  13. return l
  14. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.