Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I split a string via a select char?

In python, this is easily doable with the following code:

mystring = "hello, world, this, will, be, a, list"
mylist = mystring.split(",") # ["hello", "world", "this", "will", "be", "a", "list"]

I'm not sure how to accomplish this in lua, though. I found some code that will only list the amount of objects in the list, instead of the items themselves.

function split(inputstr, sep)
	if sep == nil then
		sep = "%s"
	end
	local t={}
	for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
		table.insert(t, str)
	end
	return t
end

To clarify any possible confusion about what I'm asking, I need to take a string with a bunch of stuff in it, except turn that string into a table, where each object is a part of the original string, and when a comma is encountered, a new object inside the table begins.

1 answer

OMG I'm so dumb! I was checking nil against nil:

if registered[location.Name] ~= nil then

You see, location is actually supposed to be a string. Sorry!

This discussion is preserved as it was. New answers, comments, and votes are closed.