You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
make a function of very time split
What is the issue? Include screenshots / videos if possible!
i can’t be
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
yes
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
function Splits(str,...)
end
print(Splits("{A,B} {B,A} {C,A},"{","}")) -- {A,B,B,A,C,A}
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
I understand what you’re referring to now. You want string.split (the built in Lua string splitting function) to work with multiple separators (or delimiters)
So I’m assuming you mean that you would want string.split to work like this:
-- This would split the string into {A, B, C}
-- Though currently with how string.split works, it would actually split it into
-- {A, B.C}
print(string.split("A!B.C", "!", "."))
Here is a quick solution to this that supports multiple delimiters.
local function SplitString(str, ...)
local response = {}
local pattern = "[^" .. table.concat({...}) .. "]+"
for word in str:gmatch(pattern) do
table.insert(response, word)
end
return response
end
print(SplitString("A!B.C", "!", ".")) -- Prints a table of {A, B, C}