Hey can someone help me with string.match, how would i compare one string to another,
EXAMPLE
s = ‘hey’
s2 = ‘Hey’
How would i compare both strings if they have the same text, even if its capitalized.
Hey can someone help me with string.match, how would i compare one string to another,
EXAMPLE
s = ‘hey’
s2 = ‘Hey’
How would i compare both strings if they have the same text, even if its capitalized.
local s = "hey"
local s2 = "Hey"
if s == s2 then -- no 'strcmp' like in C
print("the strings are equal")
else
print("the strings aren't equal :(")
end
these two links should be very helpful
It’s sort of like what @ElusiveEpix said, but different. You will need to use string.lower() or "string":lower()
local s = "hey"
local s2 = "Hey"
print(s:lower() == s2:lower()) --will print true.
there’s actually case insensitive matching in the manual.
function nocase (s)
s = string.gsub(s, "%a", function (c)
return string.format("[%s%s]", string.lower(c), string.upper(c))
end)
return s
end
print(nocase("Hi there!"))
--> [hH][iI] [tT][hH][eE][rR][eE]!
this gives a case insensitive pattern for string.match.