I need a way to add a space between two connected words

So basically, due to the way I store what materials each mineable part gives the player when mined, I cannot have any spaces in my material names. I want the name displays to have spaces between the words in my inventory system though. Is there a function that can separate words?

I want something that does this:

"IronOre" -> "Iron Ore"

You can use this function:

local function splitTitleCaps(str)
	str = str:gsub("(%u)", " %1")
	return str:gsub("^%s", "")
	
end

local res = splitTitleCaps("MyString")
print(res) --My String

It just uses some string manipulation to split at the capital words

Function from solution by @Forummer on this post:

5 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.