Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to remove words from a string?

Asked by 5 years ago

I am trying to figure out how to remove a word from string. I tried using string.sub but don't know what to do from there.

local String = "Buy Model"

if string.sub(String, 1, 4) == "Buy " then 
    --I know you can do String = string.sub(String, 5, 8) but there is multiple strings I want to remove "Buy " from
end

1 answer

Log in to vote
0
Answered by 5 years ago

I found one way to do it:

local String = "Buy Model"

if string.sub(String, 1, 4) == "Buy " then 
    local stringLength = string.len(String)
    String = string.sub(String, 5, stringLength)
    print(String) -- prints 'Model'
end
0
He did mention that he knows the string subbing method. He is referring string.gsub("word", "") GetGlobals 343 — 5y
0
Oh wait, you're the same person. My bad, refer to the wiki link: https://www.robloxdev.com/articles/Lua-Libraries/string GetGlobals 343 — 5y
Ad

Answer this question