Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to remove words from a string?

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

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

2 comments

0

He did mention that he knows the string subbing method. He is referring string.gsub("word", "")

0

Oh wait, you're the same person. My bad, refer to the wiki link: https://www.robloxdev.com/articles/Lua-Libraries/string

This discussion is preserved as it was. New answers, comments, and votes are closed.