Gsub is being silly rn

So I was using Gsub to remove part of a string from another string, heres the code:

setValue = string.split(setValue,']')[1] -- this is 4

local remove = '['..tostring(setValue)..']'
action = string.gsub(action,remove,'')
print(action,setValue,remove) 

so after I remove the stuff from action and print it I get this:

action = gravity
setvalue = 4
remove = [4]

So uh yeah the brackets arent getting removed from action

PS: action is originally set to gravity[4]

So what is going on? And how do I fix this lol

Square brackets are a string pattern, it means any of the contained items, for example:

local pattern = "[%w_]+"
--which represents any number of numbers and strings or underscores

To fix your issue and detect the square brackets, just put a percent sign before them.

local remove = "%["..tostring(setValue).."%]"
2 Likes

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