Help With Splitting String into Multiple Strings

Hey devforum! I am trying to come up with a code to convert one string into multiple strings. I checked String.split on Api, but it didn’t work. Thanks in advance, it’s probably a simple error but I’m still new to strings.

local input = {"test,10"}
local values = input:split(",") --this line errors
for i,v in pairs(values)do
	print(v)
end

--expected output : "test", "10"
--got: Script:3: attempted to call a nil number

I would assume that your problem is that you are inserting this string into a TABLE and attempting to split the TABLE, not the string.

A solution could be to just remove the curly brackets:

local input = "test,10"
local values = input:split(",") --this line errors
for i,v in pairs(values)do
	print(v)
end
3 Likes

Wow thanks, I don’t know how I missed that. Thank you so much!

1 Like