I’m trying to see if a string has “keybind:” in it, if it does, replace the single character after it with “Button A” then remove the “keybind:” after.
local function _fixToolTip(_tool:Tool)
local _splitToolTip = "press keybind:g to do something"
_splitToolTip = string.gsub(_splitToolTip, "(keybind:)[^|]*()", "%1" .. "Button A")
return _splitToolTip
end
It does remove the “g” but doesn’t remove “keybind:” and the text after it also gets removed. “press keybind:Button A”
I was able to remove the “keybind:” by using another string.gsub which looked for “keybind:” and set it to “”. I’m trying to get it to do it within one gsub, but I still haven’t got there yet.
It got rid of the rest of the text though but I managed to fix it.
local function _fixToolTip(_tool:Tool)
local function replace_char(str: string)
return str:match(":(.*)"):sub(2)
end
local _splitToolTip = "press keybind:g to do something"
local _fixedToolTip = replace_char(_splitToolTip:find("keybind:"), _splitToolTip)
_splitToolTip = string.gsub(_splitToolTip, "(press) ([keybind:])[^|]*()", "%1" .. " Button A")
return _splitToolTip.._fixedToolTip
end
print(_fixToolTip())