hi
is there a way to do like HelloWorld to be Hello World
basically spaces between Capital letters
hi
is there a way to do like HelloWorld to be Hello World
basically spaces between Capital letters
no like i want to convert HelloWorld to Hello World or like ArcOfTheElements to Arc Of The Elements
Yikes. So like there is an object name that has no spaces, and you want that object name to be the text on a textlabel but with spaces, is that what you are saying?
do you mean like a function name, like
local function TestFunc()
end
local function Test Func()
end
yes exactly, something to do with string.split
but i don’t know how to detect capitals in a string
Hmm, I am not actually sure how to do that. I apologize.
These 3 links may help:
function SpaceOut(String)
return String:gsub("(%l)(%u)", "%1 %2")
end
local NewString, Repeat = SpaceOut("HelloWorld")
print(NewString)
print(Repeat)
Another way of doing it :
local function addSpaces(String)
local newString = ""; --Place Holder for new String
for i = 1, #String, 1 do --Iterate #String times
local currentLetter = string.sub(String, i, i); --Current letter
local asciiValue = string.byte(currentLetter); -- Convert character into ascii
if(i~= 1 and i~=#String and asciiValue >= 65 and asciiValue <= 90) then
--[[
1. We do not want to add a space if the first or last letter of the string is a capital.
2. We want to add a space if the letter is between 'A'(ASCII 65) and 'Z'(ASCII 90)
]]
newString = newString..' '..currentLetter; --Add a space, and the letter to the new string
else
--No caps, just add the current letter
newString = newString..currentLetter;
end
end
return newString;
end
local a = addSpaces("HelloWorld");
print(a);