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

How would I ignore casing?

I understand you can use string:lower() or string.upper(), but that's not exactly what I'm trying to do. Example:

local var = "BRIGHT BLUE"

Now, the correct capitalization is "Bright blue" What I've noticed is that in Java you can use EqualsIgnoreCase(). Is there a similar function?

Yes, I did search the site for this. I don't see it. No downvotes please...

1 answer

✓ Accepted answer

You can compare two strings without case by using the lower or upper method on both of them.

print(("bob"):lower() == ("BOB"):lower())

To create a method.

In regular Lua you could modify string

string.equalsIgnoreCase = function(self,other)
	return self:lower() == other:lower()
end

print(("Hello"):equalsIgnoreCase("HELLO"))

Since Rbx.Lua doesn't allow modifications to string. The closest you will get to this in Rbx.Lua is:

local NewString = {}
for o,n in pairs(string) do
	NewString[o] = n
end
local E = getfenv()
E.string = NewString
setfenv(1,E)

string.equalsIgnoreCase = function(one,two)
	return one:lower() == two:lower()
end

print(string.equalsIgnoreCase("BOB","bob"))

Or just a function

equalsIgnoreCase = function(one,two)
	return one:lower() == two:lower()
end

print(equalsIgnoreCase("BOB","bob"))

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