Jump to content

Module:Sandbox/Element10101/Split

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Element10101 (talk | contribs) at 22:23, 4 June 2025 (Created page with 'local p = {} p.split = function (inputstr, sep) -- if sep is null, set it as space if sep == nil then sep = '%s' end -- define an array local t = {} -- split string based on sep for str in string.gmatch(inputstr, '([^'..sep..']+)') do -- insert the substring in table table.insert(t, str) end -- return the array return t end return p'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}

p.split = function (inputstr, sep)
   -- if sep is null, set it as space
   if sep == nil then
      sep = '%s'
   end
   
   -- define an array
   local t = {}
   -- split string based on sep   
   for str in string.gmatch(inputstr, '([^'..sep..']+)') do
      -- insert the substring in table
      table.insert(t, str)
   end
   -- return the array
   return t
end

return p