How do I get every character before and after a string?

I am trying to get every character in a string before and after ", "

So far I have tried: ExampleStringVariable:sub(1, ExampleStringVariable:find(", ") -1. However, :find returns as nil.

Does anyone know how I would go about doing this? I am trying to get the numbers before and after the , in the string. I want it to go from (1, 0.5) to Var1 = 1, Var2 = 0.5. Help is greatly appreciated, thank you!

Use :split(",") on the string. It will return a table with every value before and after every comma.

Save this data in a variable, like this

local split = text:split(",")

Then you get the index and you can do the rest with what you need.


And to remove parentheses, you use the same logic.

local split = text:split(",")

local Var1 = split[1]:split("(")[1]
local Var2 = split[2]:split(")")[1]
1 Like

Thanks for the help. Does this look right?

local Split = text:split(",")
local Before = Split[1]
local After = Split[2]

Yes. That will work, but if you have the parentheses in the string, you should follow the second half of my reply if it don’t want to have them in there.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.