Basically, I want it to print out “test+” but in the output I get “1 5”.
How do I escape the whole string without manually putting “%” before the “+” ?
Any advice?
Code:
local test1 = "test+"
local test2 = "tEsT+"
if (string.find(string.lower(test2),string.lower(test1),1,true)) ~= nil then
print(string.find(string.lower(test2),string.lower(test1),1,true))
end
i want to input ANY type of text into a field
lets say “TEST++”
the issue is i need a way to escape the ‘+’ without manually putting ‘%’ before it.
basically im looking for a string function or something that does that.
im just trying to learn string functions and stuff, theres no reason why i would specifcally choose “++” I could also be choosing “-” or “.” etc etc.
Im just trying to improve my knowledge here thats all, this stuff is used in HD admin for example and its just good for me to know, these “magic characters” are whats bothering me.
local Text = "your text" -- the text
local letter = "your letter" -- The letter that you want to check
if string.find(Text, letter) ~= nil then
print("Found something")
-- do some code here if something is detected
else
print("there is nothing")
-- do some code here if nothing is detected
end
Here’s a basic function that escapes magic characters:
local MAGIC_CHARS = {'$', '%', '^', '*', '(', ')', '.', '[', ']', '+', '-', '?'}
local function ignoreMagicCharacters(str: string): string
local cStr = ""
local char
for i = 1, string.len(str) do
char = string.sub(str, i, i)
if table.find(MAGIC_CHARS, char) then
cStr ..= "%" .. char
else
cStr ..= char
end
end
return cStr
end
print(ignoreMagicCharacters("test++")) --// test%+%+
print(ignoreMagicCharacters('something%$')) --// something%%%$