Whitemambaa

Separate string

Apr 2nd, 2014
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.54 KB | None | 0 0
  1. local function separate(str)
  2.     local tbl={}
  3.     local pos=str:find'%S'
  4.     while pos do
  5.         if str:sub(pos,pos)=="\"" then
  6.             local closingQuote=str:find("\"",pos+1)
  7.             if closingQuote then
  8.                 tbl[#tbl+1]=str:sub(pos+1,closingQuote-1)
  9.                 pos=closingQuote+1
  10.             else
  11.                 pos=pos+1
  12.                 print("No matching quote")
  13.             end
  14.         else
  15.             tbl[#tbl+1],pos=str:match("([^%s\"]+)()",pos)
  16.         end
  17.         pos=str:find("%S",pos)
  18.     end
  19.     return tbl
  20. end
  21.  
  22. print("{\""..table.concat(separate[[ This is a string. "This is also a string." Also, you're ugly. ]],"\",\"").."\"}")
Advertisement
Add Comment
Please, Sign In to add comment