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

How can I get the uppercase or lowercase capture in string.gsub?

I am working on a library extension module, and I am looking for a way to swap casing of a given string with string.gsub. If you use Python you'll know about str.swapcase(). Basically I want to write that, but in Lua.

So if you pass a string "hELLO wORLD", string.swapcase("hELLO wORLD") would yield "Hello World".

This is originally what I had:

-- this is a nested key-value pair, there is a main table, which this is in, but this is the only part u need tho
string = setmetatable({
		swapcase = function(s)
			return (s:gsub("%u" --[["%l"]])) -- i got stuck
		end
	}, { __index = string })

I was stuck here. Is there a way I can get the (upper/lower)case capture so I can change the casing to what it needs to be?

1 answer

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