How to split much times

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

make a function of very time split

  1. What is the issue? Include screenshots / videos if possible!

i can’t be

  1. 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.

Sir… please provide a more detailed description

function Splits(str,...)

end

print(Splits('{A,B} {B,A} {C,A}',"{","}",",")) -- {"A,B","B,A","C,A"}
1 Like

What are you trying to do exactly?

a split which can split a string but more args how

string.split("A,B",",") -- {A,B}

Splits("A,B C",","," ") -- {A,B,C}

What do you mean by this? You want a function that splits a string by comma?

no,

i want a function that can split a string width very characters

What? Your example shows that you want the output to split a string by comma. Can you clarify?

una división que puede dividir una cadena pero más argumentos sobre cómo

string.split("A,B",",") -- {A,B}

Splits("A,B C",","," ") -- {A,B,C}

i already said this

You’re not really making sense to be honest what is this for?

to split a string into more than one character

it’s how

print(string.split("A B"," ")) -- return {A,B}

and

print(string.split("A,B",",")) -- return {A,B}

then

print(Splits("A,B C",","," ")) -- return {A,B,C} it's splitting " " and ","

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}

Hopefully it helps! :slight_smile:

2 Likes

ok i let’s test i am very happy if yes works

my dream it’s really thanks :smiley:

Do you know how you would do this but keep the delimiters (splitters)?

1 Like