I have written a function that searches over the string, replacing matches when it finds them:
local ckey = {
["Hello"] = "-=[Hello]";
["World"] = "[World]=-";
["a"] = "--.--";
['<'] = ">>";
['>'] = "<<";
['0'] = "ZERO";
}
local read = ""
local function is_match(str, key)
for i,v in pairs(key) do
if i == str then
return v
elseif i:match("^"..str) then
read = str
return true
end
end
read = ""
end
local function replace(str, key)
local rep = ""
for i=1,str:len() do
local result = is_match(read .. str:sub(i, i), key)
rep = rep .. (not result and str:sub(i, i) or type(result) == "string" and result or "")
end
return rep
end
print(replace("Hello <a0a> World", ckey))
local ckey = {
["Hello"] = "-=[Hello]",
["World"] = "[World]=-",
["a"] = "--.--",
['<'] = ">>",
['>'] = "<<",
['0'] = "ZERO"
}
local myString = "Hello <a0a> World"
myString = string.gsub(myString, ".", ckey) -- Check every letter
myString = string.gsub(myString, "%S+", ckey) -- Check every long letter that is not a space
print(myString)
JayzYeah32’s script works, but it starts breaking when you have words that are almost the same, like “Hellooo” or “H”.