String to Argument Parser

I am currently working on a moderation script when I wrote a piece of code that allows me to convert Strings into Arguments. At the time of this post, I have not experienced any issues with it. I’m sharing it for others to use or improve on it! Please don’t be afraid to criticize me about the way I script, or if I could of made it more efficient! I would love some feedback on improvements or changes!

function ArgumentParser(...)
	local Strings = {...}
	local Arguments = {}
	for _,String in pairs(Strings) do
		String = tostring(String)
		String = string.gsub(String, "%s+", " ")
		local Length = string.len(String)
		local OnString = false
		local Start = 0
		for i=1,Length do
			if string.sub(String, i, i) ~= " " then
				if not OnString then
					OnString = true
					Start = i
				end
				if (i==Length) and OnString then
					table.insert(Arguments, string.sub(String, Start, i))
				end
			else
				if OnString then
					table.insert(Arguments, string.sub(String, Start, i-1))
					OnString = false
				end
			end
		end
	end
	return Arguments
end
2 Likes

This topic was automatically closed after 1 minute. New replies are no longer allowed.