I am trying to format a string here.
What I have: “002504”
What I want: “00.25.04”
How would I go around doing this?
I am trying to format a string here.
What I have: “002504”
What I want: “00.25.04”
How would I go around doing this?
This might be what you are looking for (However, this goes from left to right, so if you have 0000000 it would give you 00.00.00.0) :
local YourString = "000000"
local StringTable = string.split(YourString,"")
local newString = ""
for i = 1, #StringTable do
newString = newString..StringTable[i]
if i%2 == 0 and i ~= #StringTable then
newString = newString..'.'
end
end
print(newString)
I will only ever be dealing with 6 digit strings, this works perfectly!
I know this topic is already solved, but you can actually do this
newString ..= "."
Well, the shorter version of @paetemc2’s
local YourString = "000000"
local newString = YourString:gsub("(%w%w)(%w%w)", "%1.%2.")
print(newString)