Posted By

yuconner on 08/16/06


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

CobaltHex
Tyster


string split in lua


 / Published in: Lua
 

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

  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
Posted By: yuconner on September 19, 2007

-- (based on piece of code used for the QT wrapper library) local digits = split("a b c d e f g h i j k l", " ") for i=1,6 do b = self.panel:getButtonBridge("screen.button"..digits[i]) self:connect(b, b.pressed, self, self.buttonpressed,i) end

You need to login to post a comment.