Question : lua string.split
Answered by : defeated-dotterel-85pxxac1ry42
function Split(s, delimiter) result = {}; for match in (s..delimiter):gmatch("(.-)"..delimiter) do table.insert(result, match); end return result;
end
split_string = Split("Hello World!", " ")
-- split_string[1] = "Hello"
-- split_string[2] = "World!"
Source : | Last Update : Sun, 08 Mar 20
Question : lua string split
Answered by : matteo-delfavero
function stringsplit(inputstr, sep) if sep == nil then sep = "%s" end local t={} i=1 for str in string.gmatch(inputstr, "([^"..sep.."]+)") do t[i] = str i = i + 1 end return t
end
Source : | Last Update : Thu, 08 Oct 20
Question : lua split
Answered by :
-- Compatibility: Lua-5.1
function split(str, pat) local t = {} -- NOTE: use {n = 0} in Lua-5.0 local fpat = "(.-)" .. pat local last_end = 1 local s, e, cap = str:find(fpat, 1) while s do if s ~= 1 or cap ~= "" then table.insert(t, cap) end last_end = e+1 s, e, cap = str:find(fpat, last_end) end if last_end <= #str then cap = str:sub(last_end) table.insert(t, cap) end return t
end
Source : http://lua-users.org/wiki/SplitJoin | Last Update : Wed, 08 Jun 22