LPGhatguy/lemur

Add string.split()

Closed this issue · 2 comments

Missing function from Roblox standard lib.

This Lua code is identical to Roblox's implementation, to the best of my knowledge.

local function string_split(str, sep)
	local result = {}

	if sep == "" then
		for i = 1, #str do
			result[i] = str:sub(i, i)
		end
	else
		if sep == nil then
			sep = ","
		end

		local count = 1
		local pos = 1
		local a, b = str:find(sep, pos, true)

		while a do
			result[count] = str:sub(pos, a - 1)
			count = count + 1
			pos = b + 1
			a, b = str:find(sep, pos, true)
		end

		result[count] = str:sub(pos)
	end

	return result
end

Closed by #190. Thanks, @Validark and @tiffany352!