ElEditors, Interface administrators, Administrators
70,888
edits
No edit summary |
No edit summary |
||
Line 92: | Line 92: | ||
-- Implement splitting string to a table. | -- Implement splitting string to a table. | ||
function split(s, delimiter) | function split(s, delimiter, skip_empty) | ||
if not s then | if not s then | ||
return {} | return {} | ||
Line 102: | Line 102: | ||
result = {}; | result = {}; | ||
for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do | for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do | ||
table.insert(result, i, trim(match)); | if (trim(match) ~= '' and skip_empty) or skip_empty == nil then | ||
table.insert(result, i, trim(match)); | |||
i = i + 1 | |||
end | |||
end | end | ||
return result; | return result; |