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

How Can I Replace A Letter With Another Letter?

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago

There is handy gsub function for that:

local pattern = "R#X 999"
pattern = pattern:gsub( "#", "." ) -- Also known as string.gsub()
0
fyi, the 'pattern' in gsub is the "#" parameter, so `pattern` is probably not the best variable name here BlueTaslem 18071 — 8y
Ad

Answer this question