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

How Can I Replace A Letter With Another Letter?

Ok so I am creating a realistic game and now I'm playing with car numbers. I want to make it possible for police to find vehicle if they don't know one or more letters.

For example lets say that we have 3 cars in game "RBX 999" "RLX 999" and "MLG 360" And police wants to find car, he will type "R#X 999" and he will get a list of these two cars: "RBX 999" and "RLX 999".

I want "#" to be replaced with "." so I could use it as pattern in string.gmatch() how can I do it?

1 answer

✓ Accepted answer

There is handy gsub function for that:

local pattern = "R#X 999"
pattern = pattern:gsub( "#", "." ) -- Also known as string.gsub()

1 comment

0

fyi, the 'pattern' in gsub is the "#" parameter, so pattern is probably not the best variable name here

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