Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I split a string via a select char?

Asked by 5 years ago
Edited 5 years ago

In python, this is easily doable with the following code: py 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. lua 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

Log in to vote
0
Answered by 5 years ago

OMG I'm so dumb! I was checking nil against nil: lua if registered[location.Name] ~= nil then You see, location is actually supposed to be a string. Sorry!

Ad

Answer this question