Module:CommonFunctions: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 38: Line 38:


-- Implement splitting string to a table.
-- Implement splitting string to a table.
function split(pString, pPattern)
function split(s, delimiter)
  if pPattern == nil then pPattern = "," end
    if delimiter == nil then delimiter = ',' end
  local Table = {}
    result = {};
  local fpat = "(.-)" .. pPattern
    for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  local last_end = 1
        table.insert(result, match);
  local s, e, cap = pString:find(fpat, 1)
    end
  while s do
    return result;
      if s ~= 1 or cap ~= "" then
    table.insert(Table,cap)
      end
      last_end = e+1
      s, e, cap = pString:find(fpat, last_end)
  end
  if last_end <= #pString then
      cap = trim(pString:sub(last_end))
      table.insert(Table, trim(cap))
  end
  return Table
end
end
ElEditors, Administrators
70,766

edits