Split string and returns array
t = split('aaa;bbb', ';', true) -- t = {'aaa', 'bbb'}
Split string and returns result as multiple values
a, b = split.unpack('aaa;bbb', ';', true) -- a = 'aaa' b = 'bbb'
Split first substring result as 2 values
key, val = split.first('pass=hello=world', '=', true) -- key = 'pass' val = 'hello=world'
Create iterator to iterate over substrings
for word in split.each('hello world', '%s') do print(word) end
Example
-- decode header value like: -- `value1;key1=1;key2=2,value2;key1=1;key2=2` -- result: -- { -- {value1,{key=1,key2=2}}; -- {value2,{key=1,key2=2}}; -- } function decode_header(str) local res = {} for ext in split.each(str, "%s*,%s*") do local name, tail = split.first(ext, '%s*;%s*') if #name > 0 then local opt = {} if tail then for param in split.each(tail, '%s*;%s*') do local k, v = split.first(param, '%s*=%s*') opt[k] = v end end res[#res + 1] = {name, opt} end end return res end